Created
November 20, 2018 10:05
-
-
Save brennovich/093d6885661383487e162aca4f0a50ce to your computer and use it in GitHub Desktop.
This file contains 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 | |
# | |
# Simple wrapper of Redis' SCAN command. It can control batch size, patterns and cursors. | |
if [ $# -ne 3 ] | |
then | |
echo "Find matching a pattern using SCAN " | |
echo "Usage: $0 <host> <port> <pattern>" | |
exit 1 | |
fi | |
cursor=-1 | |
keys="" | |
loops=0 | |
while [ $cursor -ne 0 ]; do | |
if [ $cursor -eq -1 ] | |
then | |
cursor=0 | |
fi | |
reply=`docker run -it --rm --net=host redis:alpine redis-cli -h $1 -p $2 SCAN $cursor COUNT 10000 MATCH $3` | |
cursor=$(echo "$reply" | head -n1 | grep -o '[0-9]*[0-9]\{2,\}') | |
keys=$(echo "$reply" | tail -n $((($(echo "$reply" | wc -l) - 1))) | awk '{ print $2 }' | grep -oP '(?<=").*(?=")') | |
if [[ $keys != "" ]] | |
then | |
echo "$keys" | |
fi | |
loops=$(( loops + 1 )) | |
done | |
echo "loops : $loops" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment