redis-操作脚本

1:将redis key读出到文本中
redis-cli -c -h $host3 -p $port3 --scan --pattern "usertags_uid_*" > /tmp/node3.log

2:使用循环匹配将redis 导入到目标机器
#!/bin/bash
host=$1
port=$2
pass=$3
file=$4
if [ $# -ne 4 ];then
echo "Usage: $0 ip port pass  file"
exit
fi
cat $file|while read line
do
redis-cli -c  -h $host -p $port -a $pass del $line 
done



3:迁移key
#!/bin/bash
src_ip=xxx
src_port=6379
src_pass=x'x'x

dest_ip=xxx
dest_port=6379
dest_pass=xxx
file=$1
if [ $# -ne 1 ];then
echo "Usage: $0 file"
exit
fi
i=1
cat $file|while read line
do
    redis-cli -h $src_ip -p $src_port -a $src_pass --raw dump $line | perl -pe 'chomp if eof' | redis-cli -h $dest_ip -p $dest_port  -a $dest_pass -n 0 -x restore $line 0
    echo "$i migrate key $line"
    ((i++))
done

猜你喜欢

转载自www.cnblogs.com/monkeybron/p/11617434.html
今日推荐