TTL

Since 1.1.0Keys

Syntax

TTL key
  • Flags: fast, readonly
  • ACL categories: @fast, @generic, @keyspace, @read
  • Arity: 2

Returns how long key has before it expires, in seconds.

Reply

  • The seconds left.
  • -1 if the key has no expiry.
  • -2 if the key does not exist.

Examples

> SET a 1 EX 100
OK
> TTL a
(integer) 100
> PERSIST a
(integer) 1
> TTL a
(integer) -1
> TTL missing
(integer) -2