How do I resolve the CROSSLOT error that I receive when I use multi-key operations on an ElastiCache for Redis self-designed cluster with cluster mode turned on?

2 minutos de lectura
0

I want to resolve the CROSSLOT error that I receive when I use multi-key operations on an Amazon ElastiCache for Redis self-designed cluster with cluster mode turned on.

Short description

When you use multi-key operations on an ElastiCache for Redis self-designed cluster, you might receive the following error message:

"CROSSSLOT Keys in request don't hash to the same slot"

This error occurs when keys aren't in the same hash slot even though the keys are stored in the same node. To implement multi-key operations in a sharded ElastiCache for Redis cluster with cluster mode turned on, hash the keys to the same hash slot.

Resolution

To interact with keys that that are in different key slots, use individual commands. To interact with multiple keys in a single request on a cluster with cluster mode turned on, use hashtags to put the keys into the hash slot. When the key contains a {...} pattern, only the substring between the braces {" and "} is used to compute the hash slot. The following is an example of multiple sets that are hashed to the same hash slot:

172.31.62.135:6379> CLUSTER KEYSLOT {user1}:myset
(integer) 8106
172.31.62.135:6379> CLUSTER KEYSLOT {user1}:myset2
(integer) 8106
172.31.62.135:6379> SUNION {user1}:myset {user1}:myset2
1) "some data for myset"
2) "some data for myset2"

After you hash both sets to the same hash slot, you can perform a multi-key operation without the CROSSLOT error.

OFICIAL DE AWS
OFICIAL DE AWSActualizada hace 2 días
2 comentarios

I'm getting this error on single key operation also, how to resolve this issue?

> DEL key "myCacheEg::555 Fountain"
(error) CROSSSLOT Keys in request don't hash to the same slot
respondido hace 5 meses

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERADOR
respondido hace 5 meses