Last active
July 22, 2023 23:57
-
-
Save viniciusjssouza/de85adfc63654700157e6103c04ac19d to your computer and use it in GitHub Desktop.
Delete redis keys by pattern
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
| # replace "REPLACE_ME_IAM_KEY_PATTERN" with your key pattern that you want to delete local | |
| # to paste this in a redis-cli session, remove the new lines and put everything in an `EVAL "everythin here" 0` command | |
| local cursor='0'; | |
| local count = 0; | |
| repeat | |
| local scanResult = redis.call('SCAN', cursor, 'MATCH', 'somekey.*', 'COUNT', 100); | |
| local keys = scanResult[2]; | |
| for i = 1, #keys | |
| do | |
| local key = keys[i]; | |
| redis.replicate_commands() | |
| redis.call('DEL', key); | |
| count = count +1; | |
| end; | |
| cursor = scanResult[1]; | |
| until cursor == '0'; | |
| return count; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment