YouTip LogoYouTip

Keys Ttl

# Redis TTL Command [!(#) Redis Keys](#) The Redis TTL command returns the remaining time to live of a 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 since >= 1.0.0 ### Return value Returns -2 if the key does not exist. Returns -1 if the key exists but has no associated expire time. Otherwise, returns the remaining time to live of the key in seconds. **Note:** Prior to Redis 2.8, the command returned -1 both when the key did not exist and when the key existed without an associated expire time. ### Examples # Non-existent key redis> FLUSHDB OK redis> TTL key (integer) -2# Key exists but has no expire time set redis> SET key value OK redis> TTL key (integer) -1# Key with an expire time set redis> EXPIRE key 10086(integer) 1 redis> TTL key (integer) 10084 [!(#) Redis Keys](#)
← Keys TypeKeys Pttl β†’