How do you check basic information about a Redis key, such as its data type and remaining time to live?
Short answer
You use the TYPE command to see what kind of data type a key holds, such as string, list, or hash, and the TTL command to see how many seconds remain before the key automatically expires, returning a negative value if the key either has no expiration set or does not exist at all.
Advertisement
AModel answer
You use the TYPE command to see what kind of data type a key holds, such as string, list, or hash, and the TTL command to see how many seconds remain before the key automatically expires, returning a negative value if the key either has no expiration set or does not exist at all.
Example
TYPE mykey TTL mykey
Real-world example
A developer debugging an issue where cached data seemed to disappear too quickly checks the TTL of several keys, discovering an expiration time had been set much shorter than intended.
Likely follow-ups
- What do the different negative values returned by TTL specifically mean?
- How do you check the exact byte size a specific key is consuming in memory?
Related topics