Redis/Jedis no single point of failure and automated failover

Derek Organ picture Derek Organ · May 1, 2013 · Viewed 7.6k times · Source

In a simple situation with 3 servers with 1 master and 2 slaves with no sharding. Is there a proven solution with java and Jedis that has no single point of failure and will automatically deal with a single server going down be that master or slave(automated failover). e.g. promoting masters and reseting after the failure without any lost data.

It seems to me like it should be a solved problem but I can't find any code on it just high level descriptions of possible ways to do it.

Who actually has this covered and working in production?

Answer

FGRibreau picture FGRibreau · May 3, 2013

You may want to give a try to Redis Sentinel to achieve that:

Redis Sentinel is a system designed to help managing Redis instances. It performs the following three tasks:

  • Monitoring. Sentinel constantly check if your master and slave instances are working as expected.

  • Notification. Sentinel can notify the system administrator, or another computer program, via an API, that something is wrong with one of the monitored Redis instances.

  • Automatic failover. If a master is not working as expected, Sentinel can start a failover process where a slave is promoted to master, the other additional slaves are reconfigured to use the new master, and the applications using the Redis server informed about the new address to use when connecting.

... or to use an external solution like Zookeeper and Jedis_failover:

JedisPool pool = new JedisPoolBuilder()
    .withFailoverConfiguration(
        "localhost:2838", // ZooKeeper cluster URL
        Arrays.asList( // List of redis servers
            new HostConfiguration("localhost", 7000), 
            new HostConfiguration("localhost", 7001))) 
    .build();

pool.withJedis(new JedisFunction() {
    @Override
    public void execute(final JedisActions jedis) throws Exception {
        jedis.ping();
    }
});

See this presentation of Zookeeper + Redis.

[Update] ... or a pure Java solution with Jedis + Sentinel is to use a wrapper that handles Redis Sentinel events, see SentinelBasedJedisPoolWrapper.