Skip to content

Instantly share code, notes, and snippets.

@hughdunne
Created September 30, 2015 23:26
Show Gist options
  • Save hughdunne/dedd1b2c85d2fbec7a8f to your computer and use it in GitHub Desktop.
Save hughdunne/dedd1b2c85d2fbec7a8f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Move all keys in Redis db $1 to db $2
if [ $# != 2 ] ; then
echo "Usage: $0 <db1> <db2>"
exit 1
fi
from=$1
to=$2
testarg () {
regex='^(0|[1-9][0-9]*)$'
if ! [[ "$1" =~ $regex ]] ; then
echo "$1 is invalid value, should be an integer between 0 and 15 inclusive"
exit 1
fi
if [[ "$1" -lt 0 || "$1" -gt 15 ]] ; then
echo "From/To should be between 0 and 15 inclusive"
exit 1
fi
}
testarg $from
testarg $to
if [[ $from -eq $to ]] ; then
echo "From and To should not be the same"
exit 1
fi
redis-cli -n $1 keys '*' | sed -e 's/^/MOVE "/' -e "s/\$/\" $2/" | redis-cli -n $1 > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment