YouTip LogoYouTip

Keys Move

# Redis Move Command [!(#) Redis Keys](#) The Redis MOVE command is used to move the specified key from the current database to the given destination 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 Version >= 1.0.0 ### Return Value Returns 1 on success, 0 on failure. ### Examples # key exists in the current database redis> SELECT 0 # Redis uses database 0 by default, explicitly specified here for clarity. OK redis> SET song "secret base - Zone" OK redis> MOVE song7 1 # Move song7 to database 1(integer) 1 redis> EXISTS song7 # song7 has been moved(integer) 0 redis> SELECT 1 # Use database 1 OK redis:1> EXISTS song7 # Confirm song7 has been moved to database 1 (note the command prompt becomes "redis:1", indicating database 1 is being used)(integer) 1# When the key does not exist redis:1> EXISTS fake_key (integer) 0 redis:1> MOVE fake_key 0 # Attempt to move a non-existent key from database 1 to database 0, fails(integer) 0 redis:1> select 0 # Use database0 OK redis> EXISTS fake_key # Confirm fake_key does not exist(integer) 0# When the source and target databases have the same key redis> SELECT 0 # Use database0 OK redis> SET favorite_fruit "banana" OK redis> SELECT 1 # Use database1 OK redis:1> SET favorite_fruit "apple" OK redis:1> SELECT 0 # Use database0, and attempt to move favorite_fruit to database 1 OK redis> MOVE favorite_fruit 1 # Because both databases have the same key, MOVE fails(integer) 0 redis> GET favorite_fruit # favorite_fruit in database 0 remains unchanged"banana" redis> SELECT 1 OK redis:1> GET favorite_fr
← Keys PersistKeys Pexpireat β†’