Redis Move Command
The Redis MOVE command is used to move a key from the current database to the specified database db.
Syntax
The basic syntax of the redis Move command is as follows:
redis 127.0.0.1:6379> MOVE KEY_NAME DESTINATION_DATABASE
Available Versions
= 1.0.0
Return Value
Returns 1 if the move is successful, and 0 if it fails.
Examples
# Key exists in the current database
redis> SELECT 0 # Redis defaults to database 0, explicitly specifying it for clarity.
OK
redis> SET song "secret base - Zone"
OK
redis> MOVE song 1 # Moves song to database 1
(integer) 1
redis> EXISTS song # song has been moved
(integer) 0
redis> SELECT 1 # Uses database 1
OK
redis:1> EXISTS song # Confirms song is in database 1 (note the command prompt changed to "redis:1", indicating database 1 is in use)
(integer) 1
# When the key does not exist
redis:1> EXISTS fake_key
(integer) 0
redis:1> MOVE fake_key 0 # Attempts to move a non-existent key from database 1 to database 0, fails
(integer) 0
redis:1> select 0 # Uses database 0
OK
redis> EXISTS fake_key # Confirms fake_key does not exist
(integer) 0
# When the source database and the destination database have the same key
redis> SELECT 0 # Uses database 0
OK
redis> SET favorite_fruit "banana"
OK
redis> SELECT 1 # Uses database 1
OK
redis:1> SET favorite_fruit "apple"
OK
redis:1> SELECT 0 # Uses database 0 and attempts to move favorite_fruit to database 1
OK
redis> MOVE favorite_fruit 1 # MOVE fails because both databases have the same key
(integer) 0
redis> GET favorite_fruit # favorite_fruit in database 0 remains unchanged
"banana"
redis> SELECT 1
OK
redis:1> GET favorite_fruit # favorite_fruit in database 1 remains unchanged as well
"apple"