Redis Getset command
The Redis Getset command is used to set the value of a specified key and return its old value.
Syntax
The basic syntax of the redis Getset command is as follows:
redis 127.0.0.1:6379> GETSET KEY_NAME VALUE
Available Version
= 1.0.0
Return Value
Returns the old value of the given key. When the key has no old value, i.e. the key does not exist, returns nil.
When the key exists but is not of string type, an error is returned.
Example
First, set the value of mykey and get a substring.
redis> GETSET db mongodb # 没有旧值,返回 nil
(nil)
redis> GET db
"mongodb"
redis> GETSET db redis # 返回旧值 mongodb
"mongodb"
redis> GET db
"redis"
Redis string