Redis uses the process of querying a certain type of key number of problems, the simpler way to operate through the REDIS-CLI combined with keys, because the work mechanism of keys is generally disabled on the line, the following shell script through scan to achieve statistical functions.
Use:
1. Save the following shell scripts, such as redis_keycount.sh, to increase execution permissions
2. Execute the script with key mode parameters such as./redis_keycount.sh ' my_key_* '
#!/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 6379-x '
function process {
Echo
Index=-1
Count=0
step=100000
while ((index!=0))
Do
If [$index-le 0];then
Index=0
Fi
echo "Scan $index match 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 "Count:" $count
}
#
If [$#-ne 1];then
echo "<pars>"
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!"
329 Reads