redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.07k stars 1.19k forks source link

Elasticache cluster "CROSSLOT keys in request don't hash to same slot " #1842

Open chandank-nu opened 6 months ago

chandank-nu commented 6 months ago

Hello experts,

We're using AWS elasticache redis cluster to store query response of Apollo Graphql server v4. We're getting the following error.

image

Not sure what's causing this issue. Any inputs are highly appreciated.

Regards, Chandan

milkcoke commented 6 months ago

Hi, I'm backend developer.

Reason

Multi-Key operation is limited in cluster mode

You're using MULTI operation with multiple s keys commands.

Redis cluster (Elasticache same) has 'slot' of the keys. So If you try to multi-key based operation using 'Multi'

It's possible of 'CROSSSLOT' issue.

Because redis specific node (member of cluster) don't have all slots you input the keys (keyv:faqc:..., ['namespace:keyv'])

Solution

I have an idea application-level approach.

  1. Group by slot - keys
  2. Delegates each command to specific master node which has 'slot'

You can refer to my article \ how to resolve 'CROSS-SLOT' issue in redis cluster environment

There's example code I write.

milkcoke commented 6 months ago

This is not Apollo Graphql issue. \ It's about redis cluster mode.

SeyyedKhandon commented 4 weeks ago

For me by using {} hash tag key patterns , the issue got solved.