I'm working in a Redis cluster environment and attempted to operate on the following three keys within a single Lua script:
user:window:req:8848113672727090
user:window:8848113672727090
window:schedule:zset
Initially, when using these keys directly, I encountered the error:
CROSSSLOT Keys in request don't hash to the same slot
According to Redis cluster specifications, when multiple keys are operated on within a Lua script, they must all reside in the same hash slot. To ensure this, I modified the keys using hashtags (wrapping a common part of the key with {}). The modified keys are:
user:window:req:{8848113672727090}
user:window:{8848113672727090}
window:schedule:zset (unchanged)
After this modification, the script executed successfully. However, my question is: Why doesn't the third key, window:schedule:zset, which doesn't use a hashtag, trigger a CROSSSLOT error? I have confirmed via the CLUSTER KEYSLOT command that window:schedule:zset is assigned to a different slot than the other two keys, yet the script still runs without issues.