= 1.0.0" />



English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis TTL Command

Redis Key (Key)

The Redis TTL command returns the remaining expiration time of the 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 Version

>= 1.0.0

Return Value

When the key does not exist, it returns -2 . When the key exists but no remaining lifespan is set, it returns -1 . Otherwise, return the remaining lifespan of the key in seconds.

Note:In Redis 2.8 Previously, when the key does not exist, or the key has not set a remaining lifespan, the command would return -1 .

Online Examples

# Key does not exist
redis> FLUSHDB
OK
redis> TTL key
(integer) -2
# Key exists but no remaining lifespan is set
redis> SET key value
OK
redis> TTL key
(integer) -1
# Key has a remaining lifespan
redis> EXPIRE key 10086
(integer) 1
redis> TTL key
(integer) 10084

Redis Key (Key)