ttl

abbr.through-the-lens (camera-flash monitor) through the lens (camera flash monitor); time to live survival time; lifetime; transistor-transistor logic transistor-transistor logic

redis TTL command syntax

Function: Returns the remaining survival time (TTL, time to live) of the given key in seconds.

Syntax: TTL key

Description: Before Redis 2.8, when the key does not exist, or the key does not have a remaining survival time set, the command Both return -1 .

Available versions: >= 1.0.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 seconds.

redis TTL command example

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