Easy Tutorial
❮ Redis Backup Sorted Sets Zrange ❯

Redis TTL Command

Redis Key

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 Versions

= 1.0.0

Return Value

Note: Prior to Redis 2.8, the command returned -1 both when the key did not exist and when the key existed but had no associated expire time.

Examples

# Non-existent key

redis> FLUSHDB
OK

redis> TTL key
(integer) -2


# Key exists but has no associated expire time

redis> SET key value
OK

redis> TTL key
(integer) -1


# Key with an associated expire time

redis> EXPIRE key 10086
(integer) 1

redis> TTL key
(integer) 10084

Redis Key

❮ Redis Backup Sorted Sets Zrange ❯