redis-vl-python icon indicating copy to clipboard operation
redis-vl-python copied to clipboard

perf: replace DELETE with UNLINK in EmbeddingsCache for better memory management

Open LizerAIDev opened this issue 6 months ago • 1 comments

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: Changed client.delete(key) to client.unlink(key)
  • mdrop_by_keys: Changed pipeline.delete(key) to pipeline.unlink(key)

Async Methods

  • amdrop_by_keys: Changed await client.delete(*keys) to await client.unlink(*keys)
  • adrop_by_key: Changed await client.delete(key) to await client.unlink(key)

Why UNLINK?

UNLINK (introduced in Redis 4.0) is a non-blocking variant of DELETE that:

  1. Unlinks the key from the keyspace immediately
  2. Reclaims memory in a separate thread asynchronously
  3. Prevents blocking the Redis server when deleting large keys
  4. 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.

LizerAIDev avatar May 14 '26 12:05 LizerAIDev

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.

jit-ci[bot] avatar May 14 '26 12:05 jit-ci[bot]