You can try Redis Sentinel to achieve this:
Redis Sentinel is a system designed to manage Redis instances. It performs the following three tasks:
Monitoring Sentinel constantly checks to see if your subordinate and subordinate instances are working as expected.
Notice . Sentinel can notify the system administrator or other computer program through the API that something is wrong with one controlled instance of Redis.
Automatic transition to another resource . If the wizard does not work as expected, Sentinel can start the transition process to another resource when the slave promotes other additional slaves reconfigured to use the new wizard and applications using the Redis server reported a new address to use when connecting.
... or 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(); } });
Watch the 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 .
FGRibreau
source share