Skip to content

perf: use UNLINK instead of DEL in SearchIndex.drop_keys#615

Open
LizerAIDev wants to merge 2 commits into
redis:mainfrom
LizerAIDev:fix-drop-keys-unlink
Open

perf: use UNLINK instead of DEL in SearchIndex.drop_keys#615
LizerAIDev wants to merge 2 commits into
redis:mainfrom
LizerAIDev:fix-drop-keys-unlink

Conversation

@LizerAIDev
Copy link
Copy Markdown

@LizerAIDev LizerAIDev commented May 14, 2026

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

  • **sync ** (): →
  • **async ** (): →

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 DEL for UNLINK in cache/index key removal paths; main risk is environments using Redis versions without UNLINK support.

Overview
Switches key-removal operations from DEL/delete to Redis UNLINK to make large deletions non-blocking.

This updates EmbeddingsCache drop helpers (drop_by_key, mdrop_by_keys, adrop_by_key, amdrop_by_keys) and SearchIndex/AsyncSearchIndex drop_keys to unlink keys asynchronously, with a small docstring note added in EmbeddingsCache.drop_by_key.

Reviewed by Cursor Bugbot for commit 1ab8846. Bugbot is set up for automated code reviews on this repo. Configure here.

… 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
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.

SearchIndex.drop_keys should use UNLINK instead of DEL

1 participant