Skip to content

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

Open
LizerAIDev wants to merge 1 commit into
redis:mainfrom
LizerAIDev:perf/unlink-embeddings-cache
Open

perf: replace DELETE with UNLINK in EmbeddingsCache for better memory management#613
LizerAIDev wants to merge 1 commit into
redis:mainfrom
LizerAIDev:perf/unlink-embeddings-cache

Conversation

@LizerAIDev
Copy link
Copy Markdown

@LizerAIDev LizerAIDev commented May 14, 2026

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.

… 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
@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented May 14, 2026

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.

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.

1 participant