Trying to implement below command in nodeJS with ioredis but getting crossslot error when redis is set up in cluster mode enabled.
redisQueue.multi()
.rpush(param1, param2)
.zadd(param1, param2, param3)
.exec()
Using redis version 6.2 with AWS elasticache.
Comment From: itamarhaber
Hi @vishalailani
The error is thrown because the keys you're trying to access in the multi() belong to different slots. The cluster only supports multi-key operations within a single hash slot. To force keys into the same slot, use tags.
Comment From: vishalailani
Hi @itamarhaber,
Actually i have 1 main key and multiple keys related to that and i want to access all keys(1 by 1) with that main key. So do i need to keep all keys in same slot ? Are there any consequences of storing almost all keys in 1 slot ?
Comment From: ranshid
@vishalailani what you suggest is a non-scalable design since you basically request all keys to exist in a single place which leaves not much room to exploit the redis cluster elasticity. Usually applications are separating their keyspace across different slots (you can use hash tagging to assign subset of keys to specific slot) and balancing their load across different slots. So to your question I think you should revisit your design to separate your keyspace to smaller logical units.