GETSET
Deprecated: use SET key value GET instead.
GETSET key value
- Group
- String
- Complexity
- O(1)
- Arity
- 3 (exactly, counting the command name)
- Flags
- write, fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
GETSET stores value at key and returns the previous string, in one step:
two clients calling GETSET on the same key never both see the same old
value. Like a plain SET, it clears any time to live. New
code can use SET key value GET, which does the same and also accepts the
other SET options.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| The key held a string | Bulk string: the old value | Bulk string |
| The key did not exist | Nil bulk string | Null |
GETSET replies with a WRONGTYPE error, and stores nothing, when the key
holds a value that is not a string.
Examples
Section titled “Examples”127.0.0.1:6379> GETSET status "running"(nil)127.0.0.1:6379> GETSET status "stopped""running"127.0.0.1:6379> GET status"stopped"Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8, where it is also deprecated in favour of
SET ... GET.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.