How do I setup a connection to a Redis Sentinel server/cluster using the Jedis library?
The Jedis library is an awesome solution, unfortunately with bad documentation.
So,
@Autowired private JedisSentinelPool pool;
public void mymethod() {
Jedis jedis = null;
try {
jedis = pool.getResource();
jedis.hset(....
} catch (JedisException je) {
throw je;
} finally {
if (jedis != null) pool.returnResource(jedis);
}
}
As I am using Spring, I need:
<bean id="redisSentinel" class="redis.clients.jedis.JedisSentinelPool">
<constructor-arg index="0" value="mymaster" />
<constructor-arg index="1">
<set>
<value>hostofsentinel:26379</value>
</set>
</constructor-arg>
<constructor-arg index="2" ref="jedisPoolConfig"/>
</bean>