perf: replace Redis KEYS command with SCAN for cache invalidation #98
Labels
No Label
ai-changes-requested
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
in-next-release
status/in-progress
status/pr-open
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-v2#98
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
utils/cache.pyCacheManager.clear_prefix()(lines 190–191) uses the RedisKEYScommand for pattern-based cache invalidation:KEYSis a well-known Redis anti-pattern — it performs a full keyspace scan and blocks the Redis server for its duration. While the current keyspace is small, this is a latency risk that grows with usage and can cause spikes affecting all concurrent Redis operations.Fix
Replace with async
SCANiteration:SCANis non-blocking and iterates incrementally.Impact
LOW — Only triggered by
@cache_invalidateon write operations, and Redis is optional. But this is a correctness/scalability concern worth fixing proactively.PR #101 opened: #101
Replaced
client.keys(pattern)withasync for key in client.scan_iter(match=pattern)inCacheManager.clear_prefix(). Single-line functional change; 958 tests pass.