Latest web development tutorials

Redis Pttl command

Redis key (key)

Redis Pttl command in milliseconds return key remaining expiration time.

grammar

redis Pttl basic command syntax is as follows:

redis 127.0.0.1:6379> PTTL KEY_NAME

Available versions

> = 2.6.0

return value

When the key does not exist, it returns -2. When the key is present but not set the remaining lifetime, it returns -1. Otherwise, the remaining survival time, in milliseconds, the return key.

Note: Redis 2.8 ago, when the key does not exist or is not set key remaining lifetime, the command returns -1.

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

Redis key (key)