Redis GETSET命令在Redis鍵中設置指定的字串值,並返回其舊值。
返回值
- 返回一個字串,也就是鍵的舊值。 如果鍵不存在,則返回
nil
。
語法
下麵是Redis GETSET
命令的基本語法。
redis 127.0.0.1:6379> GETSET KEY_NAME VALUE
示例
首先,在Redis中設置一個鍵,然後設置並獲取它的舊值。
redis 127.0.0.1:6379> GETSET mynewkey "This is my test key"
(nil)
redis 127.0.0.1:6379> GETSET mynewkey "This is my new value to test getset"
"This is my test key"