src_ip=127.0.0.1 #redis 源port src_port=36379 #redis 源库 src_db=0 #redis 目的ip dest_ip=172.17.16.207 #redis 目的port dest_port=6379 #redis 目的 dest_db=0 #redis 密码 pw=30SXP pw_new=8_BF42z #要迁移的key前缀 #key_prefix=com.example.test redis-cli -h $src_ip -p $src_port -a $pw -n $src_db keys "*" | while read key do redis-cli -h $src_ip -p $src_port -a $pw -n $src_db --raw dump $key | perl -pe 'chomp if eof' | redis-cli -h $dest_ip -p $dest_port -a $pw_new -n $dest_db -x restore $key 0 echo "migrate key $key" done
2 执行sh脚本 chmod u+x
./redis_qianyi.sh