TTL

Reports a key's remaining lifetime in seconds.

Keys & expiration · Example verified

Syntax covered here

TTL key

The cases distinguish a persistent key (-1) from a missing key (-2) and check persistence after PERSIST.

Tested example & replies

Requests below run in order against an empty database. Each connection authenticates with the fixture password first. Quoted values are strings; null is a nil reply; arrays preserve RESP order.

# connection: default
> SET sample value
"OK"
# connection: default
> TTL sample
-1
# connection: default
> TTL missing
-2