Redis Keys: MOVE
Redis MOVE Command
Redis MOVE command is used to move a key from currently selected database to specified destination database. When key already exists in the destination database, or it does not exist in the source database, it does nothing. It is possible to use MOVE as a locking primitive because of this.
Here are some common uses and scenarios for the "MOVE" command:
- Database Separation: Organize and separate data across multiple databases within a single Redis instance.
- Load Balancing: Distribute keys to different databases to balance the load.
- Data Migration: Gradually migrate data from one database to another within the same Redis server.
- Environment Management: Move keys between development, staging, and production environments within the same Redis instance.
Syntax:
MOVE KEY_NAME DESTINATION_DATABASE
Available since
1.0.0.
Return Value
-
Integer reply , specifically
- 1, if the key is moved.
- 0, if the key is not moved.
Return Value Type
Integer
Example: Redis MOVE
First, create a key in redis and set some value in it.
In redis by default 0th database is selected, so now we are moving the generated key in the second database.
127.0.0.1:6379> SET key "PHP" OK 127.0.0.1:6379> MOVE key 1 (integer) 1 127.0.0.1:6379> MOVE key 1 (integer) 0
Example: Redis MOVE another example
127.0.0.1:6379> SET key1 "JavaScript" OK 127.0.0.1:6379> MOVE key1 1 (integer) 1 127.0.0.1:6379> EXISTS key1 (integer) 0 127.0.0.1:6379> SELECT 1 OK 127.0.0.1:6379[1]> GET key1 "JavaScript"
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/redis/redis-move-key-db.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics