English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Comando Getset Redis

stringa(string) Redis

Il comando Getset Redis viene utilizzato per impostare il valore di un key specifico e restituire il valore precedente del key.

Sintassi

Sintassi del comando Getset Redis

redis 127.0.0.1:6379> GETSET KEY_NAME VALUE

Versioni disponibili

>= 1.0.0

Valore di ritorno

Restituisce il valore precedente del key dato. Quando key non ha un valore precedente, ovvero key non esiste, restituisce nil.

Quando key esiste ma non è di tipo stringa, restituisce un errore.

esempio online

Prima di tutto, impostare il valore di mykey e tagliare la stringa.

redis> GETSET db mongodb    # non c'è valore precedente, restituisce nil
(nil)
redis> GET db
"mongodb"
redis> GETSET db redis      # restituisce il valore precedente mongodb
"mongodb"
redis> GET db
"redis"

stringa(string) Redis