redis cluster 批量删除key
#June 19 2020 有空结果一下原来的版本再优化一下
cat redis_del_key.sh
#!/bin/bash
# Usage
#redis_list=("host:post" "host:post")
redis_list=( "172.16.200.12:7003" "172.16.200.7:7004" "172.16.200.7:7005" "172.16.200.13:7000" "172.16.200.13:7001" "172.16.200.12:7002")
#redis_list=( "172.16.200.13:7000" "172.16.200.13:7001" "172.16.200.12:7002")
#redis_list=("172.16.200.7:7004")
password="3636password"
for info in ${redis_list[@]}
do
echo "开始执行:$info"
ip=`echo $info | cut -d : -f 1`
port=`echo $info | cut -d : -f 2`
for loop in `cat key.txt`
do
#echo $loop |xargs -t -n1 redis-cli -c -h $ip -p $port -a $password -c del
echo $loop |xargs -t -n1 redis-cli -c -h $ip -p $port -a $password -c keys
done
done
echo "success done完成"
# cat key.txt
infnce:wonderfulCache
ext_info
#原来的版本
del hello_user_*
redis-cli keys
redis-cli keys "hello_user_*" | xargs redis-cli del
./redis-cli -h IP -p PORT -a PASSWORD keys 'key*' | xargs ./redis-cli -h IP -p PORT -a PASSWORD del
redis-cli -c -h 172.31.22.218 -p 7000 -a pass keys 'hello_user_*'| xargs -i redis-cli -c -h 172.31.22.218 -p 7000 -a pass del {}
redis-cli -c -h 172.31.22.218 -p 7001 -a pass keys 'hello_user_*'| xargs -i redis-cli -c -h 172.31.22.218 -p 7001 -a pass del {}
redis-cli -c -h 172.31.16.135 -p 7002 -a pass keys 'hello_user_*'| xargs -i redis-cli -c -h 172.31.16.135 -p 7002 -a pass del {}
redis-cli -c -h 172.31.16.135 -p 7003 -a pass keys 'hello_user_*'| xargs -i redis-cli -c -h 172.31.16.135 -p 7003 -a pass del {}
redis-cli -c -h 172.31.23.43 -p 7004 -a pass keys 'hello_user_*'| xargs -i redis-cli -c -h 172.31.23.43 -p 7004 -a pass del {}
redis-cli -c -h 172.31.23.43 -p 7005 -a pass keys 'hello_user_*'| xargs -i redis-cli -c -h 172.31.23.43 -p 7005 -a pass del {}
#!/bin/bash
redis_comm=/usr/local/redis-5.0.3/bin/redis-cli
redis_ser01=192.168.50.175
redis_ser02=192.168.50.174
$redis_comm -c -h $redis_ser01 -p 7001 -a xxx keys $1 | xargs -i $redis_comm -c -h $redis_ser01 -p 7001 -a xxx del {}
$redis_comm -c -h $redis_ser02 -p 7001 -a xxx keys $1 | xargs -i $redis_comm -c -h $redis_ser02 -p 7001 -a xxx del {}
运行:
./redis_del_key.sh 匹配的key*
err
-i {} 都是一定要的
redis-cli -n 0 keys "test*" | xargs redis-cli -n 0 del
(error) CROSSSLOT Keys in request don't hash to the same slot
see also
redis集群批量删除模糊key shell脚本
redis cluster集群批量删除中的key
Redis集群批量删除key
redis集群批量删除指定的key
https://blog.csdn.net/qq_36090419/article/details/80537684