Skip to content

fix: add cluster hash-tag validation to SearchIndex.drop_keys#614

Open
algojogacor wants to merge 1 commit into
redis:mainfrom
algojogacor:fix/drop-keys-hash-tag-validation
Open

fix: add cluster hash-tag validation to SearchIndex.drop_keys#614
algojogacor wants to merge 1 commit into
redis:mainfrom
algojogacor:fix/drop-keys-hash-tag-validation

Conversation

@algojogacor
Copy link
Copy Markdown

@algojogacor algojogacor commented May 14, 2026

Summary

Fixes #601SearchIndex.drop_keys should validate cluster hash-tag co-location, consistent with drop_documents.

Root Cause

drop_keys (redisvl/index/index.py:826) called self._redis_client.delete(*keys) on a RedisCluster without checking whether all keys share a hash tag. On clustered Redis Enterprise, multi-key DEL across different hash slots raises CROSSSLOT errors or silently fails depending on the redis-py client mode.

Meanwhile, drop_documents (line 860-866) already had a guard:

if isinstance(self._redis_client, RedisCluster) and not _keys_share_hash_tag(keys):
    raise ValueError("All keys must share a hash tag when using Redis Cluster.")

This inconsistency meant SemanticCache.drop() behaved differently depending on whether callers used the keys= path (via drop_keys) or the ids= path (via drop_documents).

Fix

Added the same isinstance(self._redis_client, RedisCluster) and _keys_share_hash_tag() guard to drop_keys, raising the same ValueError with the same message.

Changes

  • redisvl/index/index.py (+7): Added cluster hash-tag validation in drop_keys method

Testing

  • The guard is identical to the one already used and tested in drop_documents
  • Single-key calls (non-list path) are unaffected — hash-tag check only applies to multi-key list path
  • Non-cluster Redis clients are unaffected — the isinstance check gates the validation

Note

Low Risk
Low risk, small guard change that only affects multi-key deletes on RedisCluster by failing fast with a clear ValueError instead of triggering cross-slot DEL behavior.

Overview
Adds Redis Cluster co-location validation to SearchIndex.drop_keys: when deleting a list of keys on RedisCluster, it now checks _keys_share_hash_tag(keys) and raises ValueError if keys span hash slots.

This aligns drop_keys behavior with drop_documents and avoids CROSSSLOT issues for multi-key DEL in clustered environments.

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

Add the same RedisCluster hash-tag validation to SearchIndex.drop_keys
that drop_documents already has. This prevents cross-slot errors when
calling drop_keys with keys that hash to different slots on a clustered
Redis deployment.

The check raises ValueError when the Redis client is a RedisCluster
instance and the provided keys don't share a hash tag, consistent with
drop_documents behavior.

Closes redis#601
@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.

SearchIndex.drop_keys does not validate cluster hash-tag co-location (inconsistent with drop_documents)

1 participant