1. 把redis集群中的 master 节点信息记录在文件 redis_object_port.info 中, 方便下一步遍历各实例中的大 keys
redis-cli -h 10.240.47.147 -p 7000 cluster nodes | grep master | awk '{print $2}' | awk -F ':' '{print " -h " $1 " -p " $2}' > redis_object_port.info
2. 遍历各个实例中的大keys ( 参数 -i 0.1, 表示每隔100条scan指令就休眠0.1s, 这样redis的ops就不会剧烈抬高,但是扫描时间会变长)
more redis_object_port.info | while read object; do redis-cli $object --bigkeys -i 0.1 ; done > redis_object_bigkey.result
++++++++++++++++++++++++++++++++脚本参数化 ++++++++++++++++++++++++++++++++++++++++++++
#!/bin/sh
# 脚本说明:
# 通过输入2个参数: redis集群中任意一个实例的 IP地址 和 端口 ,自动查询出该redis集群中的大key
IP=$1
PORT=$2
echo "" > redis_object_port.info
redis-cli -h $IP -p $PORT cluster nodes | grep master | awk '{print $2}' | awk -F ':' '{print " -h " $1 " -p " $2}' > redis_object_port.infoecho "" > redis_object_bigkey.result
more redis_object_port.info | while read object
do
redis-cli $object --bigkeys -i 0.1
done >> redis_object_bigkey.result
++++++++++++++++++++++++++++++++脚本结束 ++++++++++++++++++++++++++++++++++++++++++++