Fixes misunderstanding of how scan_iter yields keys

This commit is contained in:
Mouse Reeve 2024-08-23 18:47:31 -07:00
parent 399d3e3ccc
commit 4bab19c126

View file

@ -53,11 +53,11 @@ def erase_keys(pattern, count=1000, dry_run=False):
"""Delete all redis activity keys according to a provided regex pattern""" """Delete all redis activity keys according to a provided regex pattern"""
pipeline = r.pipeline() pipeline = r.pipeline()
key_count = 0 key_count = 0
for keys in r.scan_iter(match=pattern, count=count): for key in r.scan_iter(match=pattern, count=count):
key_count += len(keys) key_count += 1
if not dry_run: if dry_run:
for key in keys: continue
pipeline.delete(key) pipeline.delete(key)
if not dry_run: if not dry_run:
pipeline.execute() pipeline.execute()
return key_count return key_count