GETSET key value
Time complexity: O(1)
Atomically sets to value
and returns the old value stored at key
. Returns an error when exists but does not hold a string value.
redis> INCR mycounter
redis> GETSET mycounter "0"
Bulk string reply: the old value stored at , or nil
when key
did not exist.
redis> SET mykey "Hello"
- "OK"
redis> GET mykey