TTL · Valkey

TTL

Returns the expiration time in seconds of a key.

Usage

TTL key

Description

Returns the remaining time to live of a key that has a timeout. This introspection capability allows a Valkey client to check how many seconds a given key will continue to be part of the dataset.

The command returns the following values in case of errors:

See also the PTTL command that returns the same information with milliseconds resolution.

Reply

One of the following:

Complexity

O(1)

ACL Categories

@fast @keyspace @read

Examples

127.0.0.1:6379> SET mykey "Hello"
OK
127.0.0.1:6379> EXPIRE mykey 10
(integer) 1
127.0.0.1:6379> TTL mykey
(integer) 10

History

See also

COPY, DEL, DUMP, EXISTS, EXPIRE, EXPIREAT, EXPIRETIME, KEYS, MIGRATE, MOVE, OBJECT, OBJECT ENCODING, OBJECT FREQ, OBJECT HELP, OBJECT IDLETIME, OBJECT REFCOUNT, PERSIST, PEXPIRE, PEXPIREAT, PEXPIRETIME, PTTL, RANDOMKEY, RENAME, RENAMENX, RESTORE, SCAN, SORT, SORT_RO, TOUCH, TYPE, UNLINK, WAIT, WAITAOF.