Reputation: 71
My application uses AWSElastiCache for session storage. Created a redis instance (Cluster Mode Disabled) with 1 primary and 2 replica nodes. I am using Lettuce as Redis client which is internal to Spring boot to connect with Redis. I am using primary and reader endpoints of the AWSElastiCache for redis to create redis connection as per AWS recommendation.
Here is my Bean to create connection factory
@Bean
public LettuceConnectionFactory redisConnectionFactory(){
LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder()
.readFrom(ReadFrom.REPLICA_PREFERRED)
.useSsl()
.build();
RedisStaticMasterReplicaConfiguration redisStaticMasterReplicaConfiguration = new
RedisStaticMasterReplicaConfiguration(primaryEndPoint,6379);
redisStaticMasterReplicaConfiguration.addNode(readerEndPoint, 6379);
redisStaticMasterReplicaConfiguration.setPassword(redisPassword);
return new LettuceConnectionFactory(redisStaticMasterReplicaConfiguration, clientConfig);
}
It looks like reader endpoint do not equally distribute the read traffic to all replica nodes. From looking at the Cloud watch metrics, i see the CacheHits are 0 for one replica node and it appears that all of the read request are being served by only one replica node among two replica nodes. What is the recommended approach to establish the connection with Redis to efficiently utilize all replica nodes in the cluster for read operations.
Upvotes: 7
Views: 2159