question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow randomization of read candidates using Redis Cluster

See original GitHub issue

Bug 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:closed
  • Created 5 years ago
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
adityak93commented, Jun 26, 2019

@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

1reaction
stillerrrcommented, Jan 12, 2019

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 : )

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found