English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Redis Getset command is used to set the value of a specified key and return the old value of the key.
The basic syntax of the redis Getset command is as follows:
redis 127.0.0.1:6379> GETSET KEY_NAME VALUE
>= 1.0.0
Returns the old value of the given key. Returns nil when there is no old value, i.e., when the key does not exist.
Returns an error when the key exists but is not of string type.
First, set the value of mykey and truncate the string.
redis> GETSET db mongodb # No old value, returns nil (nil) redis> GET db "mongodb" redis> GETSET db redis # Returns the old value mongodb "mongodb" redis> GET db "redis"