Redis Migration Methods
Redis migration can be done through RDB dump files for simplicity, live replication for zero downtime, or the MIGRATE command for individual keys. Choose based on your dataset size and downtime tolerance.
Method 1: RDB Dump File
# On source server - trigger RDB save
redis-cli BGSAVE
# Wait for completion
redis-cli LASTSAVE
# Find and copy the dump file
DUMP_PATH=$(redis-cli CONFIG GET dir | tail -1)/$(redis-cli CONFIG GET dbfilename | tail -1)
scp "$DUMP_PATH" user@new-server:/var/lib/redis/dump.rdb
# On new server
sudo systemctl stop redis
sudo chown redis:redis /var/lib/redis/dump.rdb
sudo systemctl start redis
# Verify
redis-cli -h new-server DBSIZE
Method 2: Live Replication
# On new server, set it as replica of old server
redis-cli -h new-server REPLICAOF old-server-ip 6379
# If source requires authentication:
redis-cli -h new-server CONFIG SET masterauth "source-password"
# Monitor replication status
redis-cli -h new-server INFO replication
# Wait until master_link_status:up and master_sync_in_progress:0
# When synced, promote new server to master
redis-cli -h new-server REPLICAOF NO ONE
# Update application connection strings to new server
Method 3: RIOT (Redis Input/Output Tools)
# For complex migrations with data transformation
# Install riot
# Replicate with live monitoring:
riot replicate -s redis://source:6379 -t redis://dest:6379 --mode live
Handling Authentication
# If migrating to a server with different password:
# Set password on new server
redis-cli -h new-server CONFIG SET requirepass "new-password"
# Update application configs:
REDIS_HOST=new-server-ip
REDIS_PASSWORD=new-password
REDIS_PORT=6379
Verification
# Compare key counts
redis-cli -h old-server DBSIZE
redis-cli -h new-server DBSIZE
# Spot-check specific keys
redis-cli -h old-server GET mykey
redis-cli -h new-server GET mykey
# Check memory usage
redis-cli -h new-server INFO memory
Best Practices
- Use replication method for zero-downtime migration
- Ensure new server has enough memory for the dataset
- Update all application connection strings atomically
- Monitor for replication lag during live migration
- Keep source running until fully verified