fix(extensions-redis): ERR 'EVAL' command keys must in same slot` in Redis Cluster#2170
fix(extensions-redis): ERR 'EVAL' command keys must in same slot` in Redis Cluster#2170BG0527 wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes the ERR 'EVAL' command keys must in same slot error in Redis Cluster by wrapping the namespace portion of Redis keys in hash tags ({<ns>}). The approach is correct and well-documented — using Redis hash tags to ensure the item hash key and namespace index key always map to the same slot is the standard solution for cross-slot Lua script issues. The namespace segment validation for {, }, and NUL is appropriate. The 42 new unit tests provide excellent coverage. However, there are two issues that should be addressed: (1) the key prefix is not validated for {/} characters, which can silently break the hash tag mechanism, and (2) the key format change is a silent breaking change with no migration path for existing deployments.
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes the ERR 'EVAL' command keys must in same slot error in Redis Cluster by wrapping the namespace portion of Redis keys in hash tags ({<ns>}). The approach is correct and well-documented — using Redis hash tags to ensure the item hash key and namespace index key always map to the same slot is the standard solution for cross-slot Lua script issues. The namespace segment validation for {, }, and NUL is appropriate. The 42 new unit tests provide excellent coverage. However, there are two issues that should be addressed: (1) the key prefix is not validated for {/} characters, which can silently break the hash tag mechanism, and (2) the key format change is a silent breaking change with no migration path for existing deployments.
关联 issue
ERR 'EVAL' command keys must in same slotin Redis Cluster #2165AgentScope-Java Version
v2.0.0
Description
Background
The RedisStore implementation fails when running against a Redis Cluster. The put operation executes a Lua script (EVAL) involving two keys: the item hash key and the namespace index key. Since these keys have different prefixes (item: vs idx:), they are hashed to different slots in the cluster, causing the EVAL command to fail with ERR 'EVAL' command keys must in same slot.
Root Cause
跨 key 原子操作 vs Redis Cluster 的 slot 分片机制 。
需要两个 key(item hash + namespace index ZSET)在一个 Lua 脚本中原子更新。但 key 命名中类型前缀 item: 和 idx: 不同,导致 CRC16 哈希到不同 slot。Redis Cluster 要求 EVAL 中所有 key 必须在同一 slot,因此报错。
Fix
在 key 中使用 Redis Hash Tag {...} 语法,让 CRC16 只计算 {} 内的内容。确保同一 namespace 下的 item hash 和 namespace index 落入同一 slot,Lua EVAL 脚本在 Redis Cluster 下不再报错。
Changed files:
1.
RedisStore.javaKey layout 变更 (第240-248行):
Namespace 校验增强 (第258-266行):
2.
RedisStoreTest.java42 个测试覆盖:
Checklist
mvn spotless:applymvn test)