perf: use UNLINK instead of DEL in SearchIndex.drop_keys#615
Open
LizerAIDev wants to merge 2 commits into
Open
perf: use UNLINK instead of DEL in SearchIndex.drop_keys#615LizerAIDev wants to merge 2 commits into
LizerAIDev wants to merge 2 commits into
Conversation
… management - Replace client.delete() with client.unlink() in drop_by_key - Replace pipeline.delete() with pipeline.unlink() in mdrop_by_keys - Replace await client.delete() with await client.unlink() in async methods - UNLINK frees memory asynchronously, avoiding blocking the Redis server - Improves performance for high-throughput cache invalidation scenarios
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
currently uses , which reclaims memory synchronously on the main thread. For large key deletions (10K–1M+ keys), this causes visible latency spikes.
This PR switches to , which queues memory reclamation on a background thread, returning immediately to the caller.
Changes
Context
This is the same optimization pattern already applied to in #613, now extended to .
Closes #600.
Note
Low Risk
Low risk behavior-preserving change that swaps
DELforUNLINKin cache/index key removal paths; main risk is environments using Redis versions withoutUNLINKsupport.Overview
Switches key-removal operations from
DEL/deleteto RedisUNLINKto make large deletions non-blocking.This updates
EmbeddingsCachedrop helpers (drop_by_key,mdrop_by_keys,adrop_by_key,amdrop_by_keys) andSearchIndex/AsyncSearchIndexdrop_keysto unlink keys asynchronously, with a small docstring note added inEmbeddingsCache.drop_by_key.Reviewed by Cursor Bugbot for commit 1ab8846. Bugbot is set up for automated code reviews on this repo. Configure here.