The only caveat is to use a version of redis > 2.8.0
#!/bin/bash
# delete keys from DBN cache on port PORT starting from CUR till the end in STEP steps on host HOST

CUR=0
PGNAME=`basename $0`
STEP=10000
PORT=$1
DB=$2
HOST=$3
EXEC="/export/local/redis/bin/redis-cli"

if [[ $# -ne 3 ]]; then
    echo "usage: $PGNAME HOST PORT DB_NUMBER"
    exit 55
fi

while :
do
    $EXEC -p "$PORT" -h "$HOST" -n "$DB" scan "$CUR" COUNT "$STEP" > keybatch.txt
    CUR=$(head -1 keybatch.txt)
    echo "CUR at $CUR"
    sed 's/^/del /' keybatch.txt > del.txt
    $EXEC -p "$PORT" -h "$HOST" -n "$DBN" < del.txt | wc  -l
    sleep 1
    if [[ $CUR -eq 0 ]]; then
        exit 0;
    fi
done
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s