Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arjunKumbakkara/4b7cef3a21f5a509379d96d1bfc64d0b to your computer and use it in GitHub Desktop.
Save arjunKumbakkara/4b7cef3a21f5a509379d96d1bfc64d0b to your computer and use it in GitHub Desktop.
Beautiful and Painful Redis Cluster Migration
#set connection data accordingly
#Will only work for redis > 5.0
#Easiest way
#if it doesnt work , then try with target_db=0 for both
#Also always use -c after redis-cli . Or else the redirection wont work and it will throw (error) Move
#There are multiple ways of doing it. One is via MIGRATE command , 2nd is via DUMP and RESTORE command.
source_host=localhost
source_port=6379
source_db=0
target_host=localhost
target_port=6379
target_db=1
#copy all keys without preserving ttl!
redis-cli -c -h $source_host -p $source_port -n $source_db keys \* | while read key; do echo "Copying $key"; redis-cli -c --raw -h $source_host -p $source_port -n $source_db DUMP "$key" | head -c -1|redis-cli -c -x -h $target_host -p $target_port -n $target_db RESTORE "$key" 0; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment