Skip to content

Instantly share code, notes, and snippets.

@viniciusjssouza
Last active July 22, 2023 23:57
Show Gist options
  • Select an option

  • Save viniciusjssouza/de85adfc63654700157e6103c04ac19d to your computer and use it in GitHub Desktop.

Select an option

Save viniciusjssouza/de85adfc63654700157e6103c04ac19d to your computer and use it in GitHub Desktop.
Delete redis keys by pattern
# 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