TTL seconds

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Remaining expire time in seconds

Usage: ttl key [type].
Returns -2 if the key does not exist, and -1 if no expire time is set.
📍 type is one of string/list/set/zset/hash/stream.
      type was added in ent811. Use it.

Example

Command>set key value
Result>1
Command>expire key 5 string
Result>1
Command>ttl key string
Result>3
Command>ttl key string
Result>-2
Command>get key
Result>(nil)


Syntax

TTL key [type]

  • Available since version 1.0.0.
  • Time complexity is O(1).
  • ent811: type argument added.
Related commands SETEX, TTL, PERSIST, PSETEX, EXPIREAT, PEXPIRE, PEXPIREAT, PTTL
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< EXPIREAT TTL PEXPIRE >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.