GETSET

Redis Developer Course Redis Cloud Service Redis-Gate Server

Return its old value and store the new value at a key

GET + SET
GETSET can be used together with INCR for counting with atomic reset. For example: It gets the final value every hour, stores it at another key, and sets this key to 0.

Return value

Bulk string reply, specifically:

  • the old value stored at the key, normal return
  • (nil) if the key does not exist in the database
  • (error) WRONGTYPE Operation against a key holding the wrong kind of value: if the data type of the key is not STRINGS

Example

command>incr key
result>100
command>getset key 0
result>100
command>set another_key 100
result>OK
command>incr key
result>1

Animation

Note GETSET command is atomic.


Syntax

GETSET key value

  • Available since 1.0.0.
  • Time complexity(Logical processing time): O(1)
Related Commands SET, GET, INCR
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

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


<< GETRANGE GETSET SETBIT >>

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

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