Skip to content

fix(redis): Resolve DeleteMany failure by supporting regex matching and optimizing deletion#56

Open
IndraGunawan wants to merge 5 commits intodarkweak:mainfrom
IndraGunawan:fix-redis-is-closing
Open

fix(redis): Resolve DeleteMany failure by supporting regex matching and optimizing deletion#56
IndraGunawan wants to merge 5 commits intodarkweak:mainfrom
IndraGunawan:fix-redis-is-closing

Conversation

@IndraGunawan
Copy link
Copy Markdown

Problem

Initially, calling the /flush endpoint on the Souin API did not clear data in Redis. This happened because the API passes .+ (https://github.com/darkweak/souin/blob/master/pkg/api/souin.go#L313) to DeleteMany, but the Redis only supports glob patterns. Consequently, .+ would not match any keys in Redis.

Solution

To resolve the pattern mismatch, I've updated the logic to perform a full scan of keys and filter them locally using Go's regexp packagem, like what go-redis does. This ensures that any regex pattern passed by the upstream caller is correctly applied.

Improvements

  • Optimized Scanning: Integrated the Count parameter into the SCAN command to minimize network roundtrips during key discovery.
  • Non-blocking Batch Deletion: Replaced the blocking DEL command with UNLINK and modified the flow to send the unlink command immediately after each scan iteration. This prevents blocking the Redis server and avoids building a massive slice of keys in memory.

@darkweak
Copy link
Copy Markdown
Owner

darkweak commented Apr 8, 2026

Thanks @IndraGunawan for this PR. Can we replicate these benefits in the go-redis package aswell?

@IndraGunawan
Copy link
Copy Markdown
Author

Thanks @IndraGunawan for this PR. Can we replicate these benefits in the go-redis package aswell?

Yes, just pushed the implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants