Redis – String Getset Command

  • Post author:
  • Post category:Redis
  • Post comments:0 Comments

Redis GETSET command sets the specified string value in Redis key and returns its old value.

Return Value

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

Syntax

Following is the basic syntax of Redis GETSET command.

redis 127.0.0.1:6379> GETSET KEY_NAME VALUE

Example

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"

Leave a Reply