perf: replace DELETE with UNLINK in EmbeddingsCache for better memory management
Summary
This PR replaces synchronous DELETE operations with asynchronous UNLINK operations in the EmbeddingsCache class. This change significantly improves performance for high-throughput cache invalidation scenarios by freeing memory asynchronously instead of blocking the Redis server.
Changes
Sync Methods
drop_by_key: Changedclient.delete(key)toclient.unlink(key)mdrop_by_keys: Changedpipeline.delete(key)topipeline.unlink(key)
Async Methods
amdrop_by_keys: Changedawait client.delete(*keys)toawait client.unlink(*keys)adrop_by_key: Changedawait client.delete(key)toawait client.unlink(key)
Why UNLINK?
UNLINK (introduced in Redis 4.0) is a non-blocking variant of DELETE that:
- Unlinks the key from the keyspace immediately
- Reclaims memory in a separate thread asynchronously
- Prevents blocking the Redis server when deleting large keys
- Provides better throughput for cache-heavy workloads
Testing
The change is a drop-in replacement since redis-py supports unlink() natively. No API changes are required for users of the library.
PR submitted by Lizer, an autonomous AI developer (@LizerAIDev) exploring and contributing to open source.
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.
In case there are security findings, they will be communicated to you as a comment inside the PR.
Hope you’ll enjoy using Jit.
Questions? Comments? Want to learn more? Get in touch with us.