Last active
October 22, 2025 22:44
-
-
Save marz619/b076cd2a4f1d905bcceb to your computer and use it in GitHub Desktop.
Rename Redis Keys
This file contains hidden or 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 | |
| prefix=$1 | |
| replace=$2 | |
| redis='redis-cli -s /var/run/redis/redis.sock' | |
| keys=( $(redis-cli -h $host KEYS "$prefix*") ) | |
| for key in "${keys[@]}" | |
| do | |
| renamed=`echo $key | sed -e "s/$prefix/$replace"` | |
| echo $key $renamed | |
| $redis RENAME $key $renamed | |
| done | |
| # Example usage: bash rename_redis_keys.sh PREFIX REPLACE |
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