Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data Redis with cluster support

I want to use Spring Data Redis with my clustered setup of Redis.

Now in a pure code of Jedis to connect to the cluster of Redis nodes we have to do like:

Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
        jedisClusterNodes.add(new HostAndPort("10.7.2.242", 7003));
        jedisClusterNodes.add(new HostAndPort("10.7.2.242", 7004));
        jedisClusterNodes.add(new HostAndPort("10.7.2.242", 7005));
System.out.println("jcn set initialised");
JedisCluster jc = new JedisCluster(jedisClusterNodes);
jc.set("foo_first", "bar");
String value = jc.get("foo_first");
System.out.println(value);

This outputs to bar which is correct.

Here it is quite clear that in order to use the cluster of Redis via Jedis, we have to provide all the Ip's and Port's of the master nodes of Redis Cluster.

Now when coming to Spring backed Redis, we have some of the options, like,

JedisConnection
JedisConnectionFactory
RedisTemplate

but in reality none of these classes gives me an opportunity to give the list of Ips with ports as in the above example we gave.

Did I missed something or is there a way of handling the Redis cluster in Spring Data, also as far as I know, Sentinel and Cluster (Correct me if I am wrong) are different in their practical implementation aspect, so please don't provide the examples of Sentinels.

Thanks in advance, :)

like image 346
Ankur Verma Avatar asked Dec 08 '25 06:12

Ankur Verma


2 Answers

Support for Redis 3.0 clusters has not been integrated into spring-data-redis. The Jira ticket DATAREDIS-315 was created to track this request. It seems like cluster capability was not exposed through the JedisConnection/JedisConnectionFactory classes used by Spring so it may be a while before you see this feature done.

like image 72
riversidetraveler Avatar answered Dec 10 '25 18:12

riversidetraveler


Spring session has extended support for redis clusters now starting 1.7.1. Please refer latest reference document.

like image 45
Sanket Meghani Avatar answered Dec 10 '25 19:12

Sanket Meghani