SETEX

Redis Developer Course Redis Cloud Service Redis-Gate Server

The key is removed after specified number of seconds

This is useful for storing keys with expiration times.
Usage is SETEX key seconds value.

Return value

Simple string reply: OK

Example

command>setex key 5 value
result>OK
command>ttl key
result>2   Remaining time (seconds)
command>get key
result>(nil)   Key is removed after 5 seconds

Animation

The TTL command returns the remaining time in seconds.


Syntax

SETEX key seconds value

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

To practice the command, click here to run Redis Web Client


<< SETNX SETEX PSETEX >>

Click for a question or to see comments.  Comments :    Viewed :

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