Last active
August 12, 2016 09:03
-
-
Save bikong0411/635180fbded9a779727b5b3182086005 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$#" -lt 2 ] | |
then | |
echo "Scan keys in Redis matching a pattern using SCAN (safe version of KEYS)" | |
echo "Usage: $0 <host> [port] [database] [pattern]" | |
exit 1 | |
fi | |
host=${1:-} | |
port=${2:-6379} | |
database=${3:-0} | |
pattern=${3:-\*} | |
cursor=-1 | |
keys="" | |
while [[ "$cursor" -ne 0 ]]; do | |
if [[ "$cursor" -eq -1 ]] | |
then | |
cursor=0 | |
fi | |
reply=$(redis-cli -h "$host" -p "$port" -n "$database" SCAN "$cursor" MATCH "$pattern") | |
cursor=$(expr "$reply" : '\([0-9]*[0-9 ]\)') | |
keys=${reply##[0-9]*[0-9 ]} | |
echo $keys | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment