Redis PTTL Command
The Redis PTTL command returns the remaining time to live of a key in milliseconds.
Syntax
The basic syntax of the redis PTTL command is as follows:
redis 127.0.0.1:6379> PTTL KEY_NAME
Available Versions
>= 2.6.0
Return Value
If the key does not exist, -2 is returned. If 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 milliseconds.
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> PTTL key (integer) -2 # key 存在,但没有设置剩余生存时间 redis> SET key value OK redis> PTTL key (integer) -1 # 有剩余生存时间的 key redis> PEXPIRE key 10086 (integer) 1 redis> PTTL key (integer) 6179
Other Extensions
Redis Key