PTTL

abbr.phototransferred thermoluminescence Light energy transfer thermoluminescence, light conversion thermoluminescence

redis PTTL command syntax

Function: This command is similar to the TTL command, but it returns the remaining survival time of the key in milliseconds, not in seconds like the TTL command.

Syntax: PTTL key

Available versions: >= 2.6.0

Time complexity: O(1)

Return: When key does not exist, return -2. When the key exists but the remaining survival time is not set, -1 is returned. Otherwise, returns the remaining lifetime of key in milliseconds.

redis PTTL command example

# 不存在的 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