w3resource

Redis String: Getset

Getset key value

Redis GETSET command automatically set specified string value in redis key and returns its old value. Returns an error when key exists but does not hold a string value.

Syntax:

GETSET KEY_NAME VALUE

Available since

1.0.0.

Return Value

Simple string reply, the old value of a key. If the key does not exist, then nil is returned.

Return Value Type

String

Example: Redis GETSET

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"

Previous: GETRANGE
Next: GETBIT



Follow us on Facebook and Twitter for latest update.