perf: replace Redis KEYS with SCAN in clear_prefix (#98)
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m22s
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m22s
Closes #98 Replace blocking `client.keys(pattern)` with non-blocking `client.scan_iter(match=pattern)` to avoid full-keyspace scans that block the Redis server during cache invalidation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6c49233392
commit
df9e9bedbe
@ -188,9 +188,11 @@ class CacheManager:
|
||||
|
||||
try:
|
||||
pattern = f"{prefix}:*"
|
||||
keys = await client.keys(pattern)
|
||||
if keys:
|
||||
deleted = await client.delete(*keys)
|
||||
keys_to_delete = []
|
||||
async for key in client.scan_iter(match=pattern):
|
||||
keys_to_delete.append(key)
|
||||
if keys_to_delete:
|
||||
deleted = await client.delete(*keys_to_delete)
|
||||
logger.info(f"Cleared {deleted} cache keys with prefix '{prefix}'")
|
||||
return deleted
|
||||
except Exception as e:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user