Difficulty: Intermediate
How do you move a key, or a whole dataset, from one Redis instance to another?
For individual keys, use MIGRATE. It serializes the key, sends it to the target instance, restores it there and, unless you pass COPY, deletes it from the source, all as one blocking operation on both sides. For a whole dataset, do not loop over MIGRATE; set the new server up as a replica (REPLICAOF) or load an RDB file, then switch clients over.
MIGRATE host port key|"" destination-db timeout [COPY] [REPLACE] [AUTH password | AUTH2 username password] [KEYS key ...]
Under the hood it is DUMP on the source, RESTORE on the target, then DEL on the source:
DUMP key returns the value in Redis's internal serialization format, including an RDB version and a CRC64 checksum.RESTORE key ttl payload [REPLACE] [ABSTTL] recreates it. The TTL is carried over by MIGRATE.COPY keeps the source key; REPLACE overwrites an existing key on the target (otherwise you get a BUSYKEY error).KEYS k1 k2 ... (with an empty string in the key position) moves many keys in one call.OK, or NOKEY if none of the keys existed.The operation is atomic in the sense that the key exists in at least one instance at any time. If it times out, the key may end up in both, so retries should use REPLACE.
redis-cli --bigkeys or MEMORY USAGE.DUMP payload from a newer Redis can use an RDB version the older target cannot read, so RESTORE fails. Migrate from older to newer, not the other way.destination-db must be 0.AUTH2 (Redis 6+) is needed when the target uses ACL users.| Goal | Best tool |
|---|---|
| Move a few keys between instances | MIGRATE |
| Copy keys across Redis versions or to a managed service | DUMP/RESTORE via a script, or a tool like RIOT or RedisShake |
| Move a whole instance with minimal downtime | REPLICAOF old-host 6379 on the new server, wait for sync, then fail over |
| Restore from backup | Copy the RDB file into the data directory and start Redis |
| Rebalance a Redis Cluster | redis-cli --cluster reshard or rebalance, which uses MIGRATE slot by slot |
A common real-world task is moving a self-hosted Redis to a managed service where you cannot run REPLICAOF against it. The usual approach is a tool that reads the source via SCAN plus DUMP (or by acting as a replica) and writes RESTORE to the target, with a short dual-write or read-only window during cutover. Test the cutover on staging and verify key counts with INFO keyspace and sample checks before switching production traffic.
# Move one key to 10.0.2.15, DB 0, 5000 ms timeout
MIGRATE 10.0.2.15 6379 cart:42 0 5000
# Copy several keys, overwrite on target, authenticate as an ACL user
MIGRATE 10.0.2.15 6379 "" 0 5000 COPY REPLACE AUTH2 migrator S3cret KEYS cart:43 cart:44 session:ab12
# The manual equivalent
DUMP cart:42
# on the target:
# RESTORE cart:42 0 "<payload from DUMP>" REPLACE
The empty string in the key position switches MIGRATE to multi-key mode with KEYS. RESTORE with ttl 0 creates the key without expiry.
# On the NEW server
redis-cli -h new-redis REPLICAOF old-redis 6379
redis-cli -h new-redis INFO replication | grep -E 'master_link_status|master_sync_in_progress'
# When master_link_status:up and offsets match, stop writes on old,
# then promote the new server and repoint clients
redis-cli -h new-redis REPLICAOF NO ONE
Replication copies everything, including TTLs, without blocking clients for long, which is why it beats looping over MIGRATE for full moves.
MIGRATE, DUMP and RESTORE, Resharding, Replication-based migration, Big keys