UK [ɡet set] US [ɡɛt sɛt]
Preparation to start
redis GETSET command syntax
Function: Set the value of the given key to value and return the old value of key. When key exists but is not of type string, an error is returned.
Syntax: GETSET key value
Available versions:>= 1.0.0
Time complexity : O(1)
Return: Return the old value of the given key. When key has no old value, that is, when key does not exist, nil is returned.
redis GETSET command example
redis> GETSET db mongodb # 没有旧值,返回 nil (nil) redis> GET db "mongodb" redis> GETSET db redis # 返回旧值 mongodb "mongodb" redis> GET db "redis"