【1】直接上脚本
写的比较简单、后续可以自行优化、加参数;
如,把密码、端口、数量 、host 等信息全部参数化 变量化
#!/bin/bash source /etc/profile next_position=0 while [ 1 ] do
key_info=`redis-cli -a bfengzlgdredis2017 scan ${next_position} match upgradeGiftPopup:* count 10000` next_position=`echo ${key_info}|awk '{print $1}'` echo ${key_info}|awk '{$1=null;print }'|sed 's/ /\n/g'|sed '/^$/d'|sed 's#^#del #g' >> upgradeGiftPopup.txt if [ ${next_position} -eq 0 ];then break fi
done next_position=0 while [ 1 ] do key_info=`redis-cli -a bfengzlgdredis2017 scan ${next_position} match upgradePlayCnt:* count 10000` next_position=`echo ${key_info}|awk '{print $1}'` echo ${key_info}|awk '{$1=null;print }'|sed 's/ /\n/g'|sed '/^$/d'|sed 's#^#del #g' >> upgradePlayCnt.txt if [ ${next_position} -eq 0 ];then break fi
done
注意,我这里 这句 是有把 key 带 del 前缀的
echo ${key_info}|awk '{$1=null;print }'|sed 's/ /\n/g'|sed '/^$/d'|sed 's#^#del #g'
要是只想要名称,则去掉这句中的最后一段 sed
|sed 's#^#del #g'