-
-
Save obscurerichard/f76302a0ad8ab9b20516 to your computer and use it in GitHub Desktop.
Revisions
-
obscurerichard revised this gist
Jan 9, 2020 . 1 changed file with 23 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,33 @@ #!/usr/bin/env bash # redis-scan.sh # # Adapted by @obscurerichard from itamarhaber/scan_del.sh: # https://gist.github.com/itamarhaber/11126830 # # Thanks @czerasz and @tenlee2012 for fixes # # Usage: # ./redis-scan.sh localhost 6378 0 '*test*' # # NOTE: if your redis-cli supports '--scan' use that instead, thanks @ferico # # redis-cli --scan --pattern '*' # 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=${4:-\*} cursor=-1 keys="" echo "host=${host},port=${port},database=${database}" while [[ "$cursor" -ne 0 ]]; do if [[ "$cursor" -eq -1 ]] then @@ -21,6 +36,8 @@ while [[ "$cursor" -ne 0 ]]; do reply=$(redis-cli -h "$host" -p "$port" -n "$database" SCAN "$cursor" MATCH "$pattern") cursor=$(expr "$reply" : '\([0-9]*[0-9 ]\)') keys=${reply//$cursor/} if [ -n "$keys" ]; then echo "$keys" fi done -
obscurerichard revised this gist
Sep 17, 2015 . 2 changed files with 26 additions and 23 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ #!/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 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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +0,0 @@ -
itamarhaber created this gist
Apr 20, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ #!/bin/bash if [ $# -ne 3 ] then echo "Delete keys from Redis matching a pattern using SCAN & DEL" echo "Usage: $0 <host> <port> <pattern>" exit 1 fi cursor=-1 keys="" while [ $cursor -ne 0 ]; do if [ $cursor -eq -1 ] then cursor=0 fi reply=`redis-cli -h $1 -p $2 SCAN $cursor MATCH $3` cursor=`expr "$reply" : '\([0-9]*[0-9 ]\)'` keys=${reply##[0-9]*[0-9 ]} redis-cli -h $1 -p $2 DEL $keys done