getset
GETSET
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
 |
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).