Using jedis how to write to a specific slot/node in redis cluster

前端 未结 2 402
逝去的感伤
逝去的感伤 2021-01-14 17:53

I\'m trying to improve the performance of writing data to redis cluster. We are planning to move from redi-sentinel to cluster mode for scalability.

But, the perfor

2条回答
  •  春和景丽
    2021-01-14 18:32

    but cluster mode doesn't support pipeline

    WRONG!

    With a single pipeline, you can only send multiple commands to the same connection to the same node. It has nothing to do with whether this node is a single instance or a member of a Redis Cluster.

    So your problem should be With a single pipeline, we CANNOT send multiple commands with keys distributed on multiple slots. In order to solve that, you want those keys to be located in the same slot. How can we achieve that?

    how to know/compute (before writing to cluster) to which node/slot a particular key would be written to

    You don't need to do the math yourself. You can use Hash Tags to force multiple keys to be part of the same hash slot.

    So you only need to rename those keys, which you want to be located in the same slot, with the same Hash Tags. e.g. rename user-name and user-age to {user-id}user-name and {user-id}user-age

    See Hash Tags doc for details.

提交回复
热议问题