Connect Redis cluster with jedis

試著忘記壹切 提交于 2019-12-04 07:33:16

It's normal that you observe latency when you retrieve datas in a jedis cluster depending of the clustering strategy that you have because you will bonce from one jedis to another in order to take the datas. The red arrow, is the reason of the time added to queries in jedis cluster.

The onlyway to access to the right instance is to understand from the key the location of your datas, introduicing in the key the location exemple : "instance3/user/5" or finding the location instance performing an calculation on the keys.

JedisCluster creates it's own pooling. You can provide the configuration for the pooling when you create the JedisCluster object. From that point on, you can treat the cluster like a single instance and the requests will go to the proper cluster instance.

JedisCluster cluster - new JedisCluster(...); ... cluster.set(key, value);

Trying to figure out which instance it went to can be done by getSlot() but there's no guarantee that from one moment to the next the key you set is on the same instance. Because of failover, it could have moved.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!