Spring date redis with cluster, master to write and slave for read

903 views
Skip to first unread message

Balaji Dommaraju

unread,
Aug 21, 2015, 9:07:08 AM8/21/15
to Redis DB
Hi,

I am using spring redisTemplate and JedisConnecctionfactory, i have done with single node to read and write successfully but now it's time use cluster with master and slave, master for write and slave for read, so can any one help me to reach the requirment.



Mark Paluch

unread,
Aug 24, 2015, 2:10:51 AM8/24/15
to Redis DB
Hi Balaji,

Redis Cluster support in Spring Data Redis is in progress (see https://jira.spring.io/browse/DATAREDIS-315). The release date is TBA (https://github.com/spring-projects/spring-data-commons/wiki/Release-Train-Hopper). 
AFAIK, the initial Spring Data support for Redis Cluster does not support slave reads because of two reasons: Neither Spring Data Redis nor any Java Redis driver support slave reads for now.

I'm not sure whether/when Jedis will provide cluster slave reads. The lettuce driver has this feature within the 4.x branch (https://github.com/mp911de/lettuce/wiki/ReadFrom-Settings), but the 4.x branch is not compatible to Spring Data Redis. 

So until now, you would need to provide an own implementation on top of AbstractRedisConnection or JedisConnection for handling connections on your own and dispatching reads to the slaves.

HTH, Mark

amarjit...@verse.in

unread,
Dec 9, 2016, 5:08:23 AM12/9/16
to Redis DB
I was also trying to have ReadFrom.SLAVE with spring-data-redis 1.7 using Lettuce.
We could make ReadFrom.SLAVE in Lettuce by overriding method doGetAsyncDedicatedConnection() LettuceClusterConnection.
This works for making traffic to slaves for read. However the multiget seems to be always going to master node.
Do, we have a way to avoid going to master for the slave too.

I tried making our own LettuceClusterNodeResourceProvider that overrides the method getResourceForSpecificNode(RedisClusterNode node) and set ReadFrom.SLAVE just before returning the connection. Still it didnt help and goes to master for a multi get.

Another question is:
ClusterSlotHashUtil.isSameSlotForAllKeys() - if i provided keys which are in the same master node, it still says the keys are not in same hash slot.
Is there a bug with respect to this?
Reply all
Reply to author
Forward
0 new messages