Skip to main content
Return how many seconds remain before a key expires. Also indicates whether a key exists and whether it has an expiration set.

Syntax

TTL key

Parameters

key
string
required
The name of the key to inspect.

Return value

Return valueMeaning
N (positive integer)Key exists and will expire in N seconds
-1Key exists but has no expiration
-2Key does not exist or has already expired

Examples

>>> SET color red EX 60
OK
>>> TTL color
57

>>> SET name radish
OK
>>> TTL name
-1

>>> TTL missing
-2
Checking a key after it expires:
>>> SET temp hello EX 2
OK
>>> TTL temp
1

# (after 2 seconds)
>>> TTL temp
-2

Notes

TTL implements passive expiry. If the key has expired at the time of the call, it is deleted from the hash table and -2 is returned.
Use SET with the EX option to assign or update a key’s TTL. There is no standalone EXPIRE command in RadishDB.

Build docs developers (and LLMs) love