GETSET

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

Get and set in one command

GET + SET
Often used together with the INCR command.
For example, every hour you get the latest value, store it in another key, and SET this key to 0.

Example

Command>incr key
Result>100
Command>getset key 0
Result>100
Command>incr key
Result>1

View animation

Note This command is atomic.

Redis 6.2 added the GET option to the SET command. It works the same as GETSET.
GETSET is expected to be deprecated.


Syntax

GETSET key value

  • Available since version 1.0.0.
  • Time complexity is O(1).
Related commands SET, GET, INCR
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< STRALGO GETSET LISTS Introduction >>
Email 답글이 올라오면 이메일로 알려드리겠습니다.