SETEX

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

Delete data after a given time: specify seconds

The data is deleted after the specified number of seconds.
This is useful when storing data that has an expiration time.
Usage is SETEX key seconds value.

Example

Command>setex key 5 value
Result>OK
Command>ttl key
Result>2   remaining time in seconds
Command>get key
Result>(nil)   data deleted after 5 seconds

View animation

TTL reports the remaining time in seconds.


Syntax

SETEX key seconds value

  • Available since version 2.0.0.
  • Time complexity is O(1).
Related commands SET, PSETEX, TTL, EXISTS
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< SETNX SETEX PSETEX >>

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