2

Using Lettuce, how do we configure Spring Data Redis running on host x at port 6379 and slave running on the same or different host but at port 6380?

mp911de
  • 17,546
  • 2
  • 55
  • 95
gcpdev-guy
  • 460
  • 1
  • 10
  • 23

1 Answers1

7

That's a feature which will be included in the upcoming Spring Data Redis 2.1 release. You would configure LettuceConnectionFactory similar to:

    LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
                                                    .readFrom(ReadFrom.REPLICA)
                                                    .build();

    LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration("x", 6379),
                                                    configuration);

Lettuce auto-discovers masters and replicas from a static (not managed with Redis Sentinel) setup.

mp911de
  • 17,546
  • 2
  • 55
  • 95
  • What is this LettuceTestClientConfiguration class here ? i went through some documentation but there isnt any easy way to configure and use Lettuce with Master Slave. I tried using StatefulRedisMasterSlaveConnection but again it needs RedisCodec as its parameter which makes it harder to use with different datatypes. I want to have RedisTemplate kind of abstraction for master slave setup, is there any way to achieve that ? – omjego Nov 22 '18 at 18:49
  • That’s a typo. Fixed now. – mp911de Nov 22 '18 at 19:04
  • Configure the appropriate ReadFrom. – mp911de Nov 23 '18 at 16:07
  • "SLAVE_PREFERRED"s documentation says "read preferred from slaves and fall back to master if no slave is not available.", does that mean if slave is busy serving another request then use MASTER ? – omjego Nov 26 '18 at 12:53
  • No, this means that if a replica is down (no replica configured in the topology, connection to the replica is disconnected), then reads are routed to the master. – mp911de Nov 26 '18 at 14:05
  • ReadFrom.SLAVE is deprecated – aswzen Apr 16 '21 at 12:09