Redis TTL Command
The Redis TTL command returns the remaining expiration time of a key in seconds.
Syntax
The basic syntax of the Redis TTL command is as follows:
redis 127.0.0.1:6379> TTL KEY_NAME
Available Versions
>= 1.0.0
Return Value
When the key does not exist, -2 is returned. When the key exists but has no remaining time to live set, -1 is returned. Otherwise, the remaining time to live of the key is returned in seconds.
Note:Before Redis 2.8, the command returned -1 both when the key did not exist and when the key had no remaining time to live set.
Examples
# 不存在的 key redis> FLUSHDB OK redis> TTL key (integer) -2 # key 存在,但没有设置剩余生存时间 redis> SET key value OK redis> TTL key (integer) -1 # 有剩余生存时间的 key redis> EXPIRE key 10086 (integer) 1 redis> TTL key (integer) 10084
Other Extensions
Redis Key