Last active
January 7, 2023 08:14
-
-
Save marz619/b076cd2a4f1d905bcceb to your computer and use it in GitHub Desktop.
Rename Redis Keys
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 | |
# args | |
host=$1 | |
shift | |
prefix=$1 | |
shift | |
# from=$1 | |
# shift | |
# to=$1 | |
# shift | |
echo "using host: $host" | |
# echo "replacing '$from' --> '$to'" | |
keys=( $(redis-cli -h $host KEYS "$prefix*") ) | |
# echo $keys | |
for key in "${keys[@]}" | |
do | |
renamed=`echo $key | sed -e "s/^"\(.*\)"$/\1/' -e 's/$from/$to/g"` | |
echo $key $renamed | |
redis-cli -h $host RENAME $key $renamed | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working code
Example:
bash redis_rename_keys.sh SANDBOX PRODUCTION