As we all know, the pipeline mechanism provides a good performance of the interaction between the redis client and server. Admittedly, it has been applied in many projects. My question is whether the pipeline way supports redis server with cluster mode or not?
2
Answers
Yes you can, but it’s limited to keys in the same slot. See more here Using jedis how to write to a specific slot/node in redis cluster
My original answer https://stackoverflow.com/a/72971327/5807561
Copy below:
Yes you can use pipeline in cluster mode as long as key hashes to same keyslot (not node).
To achieve keys hashing to same slot you can use hash tags. TLDR – if you have curly brackets in your key {} hash function will only be applied to that part https://redis.io/docs/reference/cluster-spec/#hash-tags
In my particular case I needed to put countries and cities by id into the redis which totaled 150k records. This is how I did it (nodejs + ioredis):