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

Comando MOVE di Redis

Key (Chiave) di Redis

Il comando MOVE di Redis viene utilizzato per spostare una chiave dal database corrente al database specificato.

Sintassi

Sintassi di base del comando MOVE di Redis

redis 127.0.0.1:6379> MOVE KEY_NAME DESTINATION_DATABASE

Versioni disponibili

>= 1.0.0

Valore di ritorno

Ritorna 1 in caso di successo, 0 in caso di fallimento.

Esempio online

# La chiave esiste nel database corrente
redis> SELECT 0                             # Redis utilizza il database 0 per default, per chiarezza viene specificato nuovamente.
OK
redis> SET song "secret base - Zone"
OK
redis> MOVE song 1                          # Sposta song nel database 1
(integer) 1
redis> EXISTS song                          # song è stato rimosso
(integer) 0
redis> SELECT 1                             # Usa il database 1
OK
redis:1> EXISTS song                        # Verifica che song sia stato spostato nel database 1 (notare che il prompt di comando è cambiato a "redis:1", indicando che si sta utilizzando il database 1)
(integer) 1
# Quando la chiave non esiste
redis:1> EXISTS fake_key
(integer) 0
redis:1> MOVE fake_key 0                    # Tentativo di spostare una chiave inesistente dal database 1 al database 0, fallito
(integer) 0
redis:1> select 0                           # Usa il database 0
OK
redis> EXISTS fake_key                      # Verifica che fake_key non esista
(integer) 0
# Quando il database sorgente e il database di destinazione hanno la stessa key
redis> SELECT 0                             # Usa il database 0
OK
redis> SET favorite_fruit "banana"
OK
redis> SELECT 1                             # Usa il database 1
OK
redis:1> SET favorite_fruit "apple"
OK
redis:1> SELECT 0                           # Usa il database 0 e tenta di spostare favorite_fruit al database 1
OK
redis> MOVE favorite_fruit 1                # Perché due database hanno la stessa key, MOVE fallisce
(integer) 0
redis> GET favorite_fruit                   # favorite_fruit del database 0 non cambia
"banana"
redis> SELECT 1
OK
redis:1> GET favorite_fruit                 # favorite_fruit anche nel database 1
"apple"

Key (Chiave) di Redis