Created
November 19, 2014 08:05
-
-
Save akunzai/9abbb632c7cfb9cd17ef to your computer and use it in GitHub Desktop.
move redis elements from db to another db (local)
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 | |
if [ "$1" == "" ]; then | |
echo "Usage: $0 [src db] [dest db]" | |
exit 0 | |
else | |
srcdb="$1" | |
fi | |
if [ "$2" == "" ]; then | |
destdb="1" | |
else | |
destdb="$2" | |
fi | |
REDIS=$(which redis-cli) | |
CURSOR=-1 | |
while [ $CURSOR -ne 0 ]; do | |
if [ $CURSOR -lt 0 ];then | |
CURSOR=0 | |
fi | |
IFS=$'\n'; | |
KEYS=($(${REDIS} -n $srcdb --raw scan $CURSOR)) | |
CURSOR=${KEYS[0]} | |
IFS=' '; | |
for KEY in ${KEYS[@]:1}; do | |
echo MOVE $KEY $destdb $(${REDIS} -n $srcdb --raw move $KEY $destdb) | |
done | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment