Allow randomization of read candidates using Redis Cluster
See original GitHub issueBug Report
Current Behavior
I am trying to connect to Redis cluster with 5 slave nodes and 1 master. All read queries are redirected to only one slave throughout the application scope.
Input Code
- Java/Kotlin/Scala/Groovy/… or Repo link if applicable:
// connection pool creation:
GenericObjectPool<StatefulRedisClusterConnection<String, String>> connectionPool;
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMinIdle(8);
poolConfig.setMaxIdle(8);
poolConfig.setMaxTotal(16);
poolConfig.setMinEvictableIdleTimeMillis(1000*30);
poolConfig.setSoftMinEvictableIdleTimeMillis(1000*30);
poolConfig.setMaxWaitMillis(0);
connectionPool = ConnectionPoolSupport.createGenericObjectPool(() -> {
logger.info("Requesting new StatefulRedisClusterConnection "+System.currentTimeMillis());
return redisClient.connect();
}, poolConfig);
//
public StatefulRedisClusterConnection<String, String> getConnection() throws Exception{
StatefulRedisClusterConnection<String, String> connection =connectionPool.borrowObject();
connection.setReadFrom(ReadFrom.SLAVE);
return connection;
}
Expected behavior/code
It should distribute read queries on all slaves.
Environment
- Lettuce version(s): 5.1.0.M1
- Redis version: 3.2.10
Possible Solution
Additional context
Issue Analytics
- State:
- Created 5 years ago
- Comments:22 (11 by maintainers)
Top Results From Across the Web
Lettuce Reference Guide
You can read this reference guide in a linear fashion, or you can skip ... Allow randomization of read candidates using Redis Cluster....
Read more >Promoting a read replica to primary, for Redis (cluster mode ...
You can promote a Redis (cluster mode disabled) read replica to primary using the AWS Management Console, the AWS CLI, or the ElastiCache...
Read more >lettuce-io/Lobby - Gitter
Hi. I have a big map stored in redis. Would it be preferable to use hgetall with StreamingChannel instead of just hgetall to...
Read more >Scaling with Redis Cluster
Redis Cluster provides a way to run a Redis installation where data is automatically sharded across multiple Redis nodes. Redis Cluster also provides...
Read more >Redis 2.6 release - GitHub
[FIX] Allow writes from scripts called by AOF loading in read-only slaves. * [FIX] Sentinel: ... 2) Not reconfigured reappearing master using Sentinel....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mp911de @smoomrik AWS has recently introduced reader endpoints for Redis which manages distribution of reads among the slaves. You can check more details here: https://aws.amazon.com/about-aws/whats-new/2019/06/amazon-elasticache-launches-reader-endpoint-for-redis/
Might want to check this out. Using this should help avoid having to provide individual replica endpoints in the application giving more flexibility.
Not sure about exact underlying implementation of this on AWS side. Waiting for more clarification. Initial tests which we have done on test environment (1 master, 2 replicas) showed roughly equal distribution of load among the 2 replicas
Just give advice, if some one uses the lettuce like this, he need pay attention to increasing the refresh period or set “false” for refresh. no need to change the code. thanks : )