标题:[实践OK]统计redis中某类key的数量,代替keys指令 出处:向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除 时间:Sat, 29 Dec 2018 15:44:37 +0000 作者:jackxiang 地址:https://jackxiang.com/post/10011/ 内容: SCAN 0 MATCH SESS_* COUNT 10 redis-cli -p 6401 -a X**--scan --pattern "SESS*" > /tmp/10.71.1*.3*_SESS_KEYS_ALL.txt #!/bin/bash A=$0 B=${A##*/} C=${B%.*} running_file_name=$C running_flag="run.$running_file_name" REDIS_CLIENT='redis-cli -h 0.0.0.0 -p 6400 -x' function process { echo $0 index=-1 count=0 step=100000 while ((index!=0)) do if [ $index -le 0 ];then index=0 fi echo "scan $index match $1 count $step" | $REDIS_CLIENT > $running_file_name.cache read index <<< `head -1 $running_file_name.cache` read inc <<< `cat $running_file_name.cache | wc -l` inc=$((inc - 1)) if [ $? -ne 0 ];then break fi count=$((count + inc)) done echo "$1 count:"$count } # if [ $# -ne 1 ];then echo "$0 " exit 0 fi # if [ -f "$running_flag" ] ; then echo "is running..." exit 0 fi # touch $running_flag # echo "processing...." echo $* process $* # rm -rf $running_flag # echo "ok!" ./redis_keycount.sh 'SESS*' processing.... SESS* ./redis_keycount.sh SESS* count:21798578 ok! 来自:https://studygolang.com/articles/14275?fr=sidebar Generated by Jackxiang's Bo-blog 2.1.1 Release