Redis TTL command is used to get the remaining time of the key expiry in seconds.
Return Value
Integer value TTL in milliseconds, or a negative value.
- TTL in milliseconds.
- -1, if key does not have expiry timeout.
- -2, if key does not exist.
Syntax
Following is the basic syntax of Redis TTL command.
redis 127.0.0.1:6379> TTL KEY_NAME
Example
First, create a key in Redis and set some value in it.
redis 127.0.0.1:6379> SET Adglobname redis OK
Now, set the expiry of the key, and later check the remaining expiry time.
redis 127.0.0.1:6379> EXPIRE Adglobname 60 1) (integer) 1 redis 127.0.0.1:6379> TTL Adglobname 1) (integer) 59