fix: add cluster hash-tag validation to SearchIndex.drop_keys - #614
fix: add cluster hash-tag validation to SearchIndex.drop_keys#614algojogacor wants to merge 1 commit into
Conversation
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
|
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. |
|
Hi, thanks for your contribution - please rebase onto |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 79a77cf. Configure here.
| ) and not _keys_share_hash_tag(keys): | ||
| raise ValueError( | ||
| "All keys must share a hash tag when using Redis Cluster." | ||
| ) |
There was a problem hiding this comment.
Async drop_keys skips hash-tag check
Medium Severity
The new cluster hash-tag guard is only applied on sync drop_keys. AsyncSearchIndex.drop_keys still issues a multi-key delete without that check, so cluster callers of SemanticCache.adrop() can still hit CROSSSLOT while the matching sync path raises ValueError.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 79a77cf. Configure here.


Summary
Fixes #601 —
SearchIndex.drop_keysshould validate cluster hash-tag co-location, consistent withdrop_documents.Root Cause
drop_keys(redisvl/index/index.py:826) calledself._redis_client.delete(*keys)on a RedisCluster without checking whether all keys share a hash tag. On clustered Redis Enterprise, multi-keyDELacross different hash slots raisesCROSSSLOTerrors or silently fails depending on the redis-py client mode.Meanwhile,
drop_documents(line 860-866) already had a guard:This inconsistency meant
SemanticCache.drop()behaved differently depending on whether callers used thekeys=path (viadrop_keys) or theids=path (viadrop_documents).Fix
Added the same
isinstance(self._redis_client, RedisCluster) and _keys_share_hash_tag()guard todrop_keys, raising the sameValueErrorwith the same message.Changes
redisvl/index/index.py(+7): Added cluster hash-tag validation indrop_keysmethodTesting
drop_documentsisinstancecheck gates the validationNote
Low Risk
Small, localized guard mirroring existing drop_documents behavior; no changes to standalone Redis or single-key deletes.
Overview
SearchIndex.drop_keysnow rejects multi-key deletes onRedisClusterwhen the keys do not share a hash tag, using the same_keys_share_hash_tagcheck andValueErrormessage asdrop_documents.This avoids cross-slot
DELfailures (or inconsistent client behavior) when callers pass a list of raw Redis keys, and aligns cache/index deletion paths that usedrop_keyswith those that usedrop_documents. Single-key deletes and non-cluster clients are unchanged; validation runs only for list inputs on a cluster client.Reviewed by Cursor Bugbot for commit 79a77cf. Bugbot is set up for automated code reviews on this repo. Configure here.