Skip to content

Instantly share code, notes, and snippets.

@akunzai
Created November 19, 2014 08:05
Show Gist options
  • Save akunzai/9abbb632c7cfb9cd17ef to your computer and use it in GitHub Desktop.
Save akunzai/9abbb632c7cfb9cd17ef to your computer and use it in GitHub Desktop.
move redis elements from db to another db (local)
#!/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