Count the number of key types in Redis instead of the keys directive

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.