Skip to content

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

Merged
darkweak merged 5 commits into
darkweak:mainfrom
IndraGunawan:fix-redis-is-closing
Jun 5, 2026
Merged

darkweak merged 5 commits into
darkweak:mainfrom
IndraGunawan:fix-redis-is-closing

Conversation

@IndraGunawan

Copy link
Copy Markdown
Contributor

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

darkweak commented Apr 8, 2026

Copy link
Copy Markdown
Owner

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

@IndraGunawan

Copy link
Copy Markdown
Contributor Author

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

Yes, just pushed the implementation

@darkweak
darkweak merged commit 46a7f24 into darkweak:main Jun 5, 2026
9 checks passed
@darkweak

darkweak commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Thank you @IndraGunawan !

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