数据库
首页 > 数据库> > redis key迁移

redis key迁移

作者:互联网

#!/bin/bash

#redis 源ip
src_ip=127.0.0.1
#redis 源port
src_port=6379

#redis 目的ip
dest_ip=10.100.0.101
#redis 目的port
dest_port=6379

password=123456
#要迁移的key前缀
key_prefix=

i=1

redis-cli -h $src_ip -p $src_port -a $password  keys "${key_prefix}*" | while read key
do
  redis-cli -h $dest_ip -p $dest_port -a $password del $key
  redis-cli -h $src_ip -p $src_port -a $password --raw dump $key | perl -pe 'chomp if eof' | redis-cli -h $dest_ip -p $dest_port -a $password -x restore $key 0
  echo "$i migrate key $key"
  ((i++))
done

标签:src,dest,ip,redis,key,迁移,port
来源: https://www.cnblogs.com/txtp/p/16434520.html