Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

GETSET

Last updated

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.

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.

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"

Same as Redis 7 and Valkey 8, where it is also deprecated in favour of SET ... GET.

SET, GET, GETDEL