Created
September 28, 2016 15:14
-
-
Save neoshrew/a4854ff8eceac4cd571797c6f5a7473e 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
#!/usr/bin/env bash | |
set -eu -o pipefail | |
HOST=172.17.0.6 | |
REDIS_CMD=(redis-cli -h "$HOST" scan) | |
CMD_EXTRA=() | |
if [[ ! -z ${1:-} ]]; then CMD_EXTRA+=(MATCH "$1"); fi | |
if [[ ! -z ${2:-} ]]; then CMD_EXTRA+=(COUNT "$2"); fi | |
export CMD_EXTRA | |
CURSOR=0 | |
while true; | |
do | |
CMD=("${REDIS_CMD[@]}" $CURSOR) | |
if [ ${#CMD_EXTRA[@]} -gt 0 ]; | |
then | |
CMD+=("${CMD_EXTRA[@]}") | |
fi | |
{ | |
read cursor | |
CURSOR=$cursor | |
while read item; | |
do | |
if [[ ! -z $item ]]; then echo $item; fi; | |
done ; | |
}< <("${CMD[@]}") | |
if [ "$CURSOR" -eq 0 ]; then break; fi; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment