The crossslot keys in request don't hash to the same slot
error occurs when you try to perform an operation that involves multiple keys in a Redis Cluster, but those keys do not belong to the same hash slot. Redis Cluster distributes data across several nodes using hash slots. When an operation requires multiple keys, all the involved keys must map to the same hash slot for the operation to be executed atomically and consistently. This error message indicates that some of the keys in your request are mapped to different hash slots, which is preventing the operation from being executed.
To resolve this error, you can follow these steps:
{...}
key tags: If your operation needs to involve multiple keys, you can enforce them to be hashed to the same slot by using the same prefix within curly braces ({...}
) in the key names. For instance, if you have keys like user:{123}:username
and user:{123}:email
, both will be guaranteed to be on the same hash slot because the content inside the curly braces is identical.Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.