Search code examples
javaredisjedisredis-sentinel

Redis Sentinel and ShardedJedis for ShardedJedisPipeline


I was initially using Redis in cluster mode at production. But later I realised that if I use Redis independent servers using ShardedJedis java API, I can use ShardedJedisPipeline which has better performance due to obvious reasons. But while using Redis Server to maintain automatic fail over and high availability, I must use Redis Sentinel. So, I started looking into Sentinel. But while doing the initial POC, I got to know that I can not use ShardedJedis and Sentinel at the same time.

Now it seems that all my paths are closed as

  1. Redis Cluster does not support Pipeline
  2. I can not achieve high availability and automatic fail over without Sentinel
  3. I can not use Sentinel with ShardedJedis.

Please correct me if I am wrong anywhere and please suggest me the best strategy to achieve performance as well as high availability and automatic fail over.


Solution

  • Spoken in general terms:

    • Redis Cluster supports Pipelining the same way like Redis Standalone does. The important part here is to hit the right node when issuing commands with keys. Commands without keys (such as MULTI or EXEC) are a no-go for Redis Cluster
    • The HA-Part is not 100% correct. While it's true, that Redis Cluster has no HA-Registry like Redis Sentinel, the Cluster itself maintains a topology. If using masters and slaves, it's not a big deal to do a client-failover to the new master. The only trick here is, to find the right moment and to update the cluster view accordingly.

    AFAIK, Redisson has an automated topology-update mechanism. I'm not sure, whether Jedis updates it's cluster view on a regular basis, but it's possible to do this manually. lettuce has a auto-reconnect feature and the automated cluster view update is scheduled for the 3.3 release

    HTH.