Latest web development tutorials

Redis Getset command

Redis string (string)

Redis Getset command is used to set the value of the specified key, and returns the old value of the key.

grammar

redis Getset basic command syntax is as follows:

redis 127.0.0.1:6379> GETSET KEY_NAME VALUE

Available versions

> = 1.0.0

return value

Returns the key of the old value. When no old key value, that key does not exist, it returns nil.

When the key is present but is not a string type, an error is returned.

Examples

First, set the value mykey and interception string.

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"

Redis string (string)