Redis Client

There are good java clients available for the Redis. Jedis is used here for the discussion. If maven is used for the build tool management, check out the list of jedis release version.

Include in your POM file:

<!-- -->

Sentinel Deployment Example

Sentinel provide high availabity for Redis. Certain extends of failure condition is handle by Sentinel without human interaction.

These are basic capabilities of the sentinel:

  • Monitoring - Sentinel constantly checks if your master and slave instances are working as expected.
  • Notification - Sentinel can notify the system administrator, another computer programs, 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.
  • Configuration provider - Sentinel acts as a source of authority for clients service discovery: clients connect to Sentinels in order to ask for the address of the current Redis master responsible for a given service. If a failover occurs, Sentinels will report the new address.

Check out the Redis Sentinel Nodes for the example deployment.

Spring Configuration

The following is using java configuration. XML configuration should be pretty to convert from this.

Lets assume that the sentinel properties are defined in in the classpath.

# Pool Configuration
redis.pool.max-active = 128
redis.pool.max-idle = 20
# Define the sentinels nodes = redis.node1
redis.sentinel.node.1.port = 26381 = redis.node2
redis.sentinel.node.2.port = 26382 = redis.node3
redis.sentinel.node.3.port = 26383

Use yaml structure for defining n nodes. This is make it easier for the real deployment to add new nodes and change the java configuration to loop each nodes.

			host:	redis.node1
			port:	26381
			host:	redis.node2
			port:	26382
			host:	redis.node3
			port:	26383

Sentinels Config

Get the properties values from the and constuct the RedisSentinelConfiguration.

// Construct the RedisSentinelNodes by getting the properties.
RedisSentinelNodes sentinelNodes() {
	List<RedisSentinelNode> nodes = new ArrayList<RedisSentinelNode>();

	for (int i=1; i<=3;i++) {
		String hostProp = "redis.sentinel.node."+i+".host";
		String portProp = "redis.sentinel.node."+i+".port";

		RedisSentinelNode redisSentinelNode = new RedisSentinelNode(
				env.getProperty(portProp, Integer.class));


	RedisSentinelNodes redisSentinelNodes = new RedisSentinelNodes(nodes);
	return redisSentinelNodes;

// Construct the RedisSentinelConfiguration using all the nodes in RedisSentinelNodes
RedisSentinelConfiguration sentinelConfiguration () {
	RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration()

	List<RedisSentinelNode> nodes = sentinelNodes().getRedisSentinelNodes();
	for (RedisSentinelNode sn : nodes ) {

	return sentinelConfig;

Jedis Connection Bean

RedisConnectionFactory jedisConnectionFactory() {

	JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(sentinelConfiguration());

	JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
	jedisPoolConfig.setMaxTotal(env.getRequiredProperty("redis.pool.max-active", Integer.class));
	jedisPoolConfig.setMaxIdle(env.getRequiredProperty("redis.pool.max-idle", Integer.class));
	return jedisConnectionFactory;

Redis Template Bean

public RedisTemplate<?, ?> redisTemplate() {
	RedisTemplate<?, ?> redisTemplate = new RedisTemplate<>();
	return redisTemplate;

Reference : Redis Sentinel Documentation