如何使用主终端节点和读取器终端节点连接到 AWS ElastiCache

dk1*_*115 7 redis spring-data lettuce amazon-elasticache spring-data-redis

我的应用程序使用 AWSElastiCache 进行会话存储。创建了一个具有 1 个主节点和 2 个副本节点的 Redis 实例(已禁用集群模式)。我使用 Lettuce 作为 Spring boot 内部的 Redis 客户端来与 Redis 连接。我正在使用 AWSElastiCache for redis 的主要端点和读取器端点来按照 AWS 建议创建 Redis 连接。

https://aws.amazon.com/about-aws/whats-new/2019/06/amazon-elasticache-launches-reader-endpoint-for-redis/

这是我用来创建连接工厂的 Bean

@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);
    }
Run Code Online (Sandbox Code Playgroud)

看起来读取器端点没有将读取流量平均分配到所有副本节点。通过查看云监视指标,我发现一个副本节点的 CacheHits 为 0,并且似乎所有读取请求都由两个副本节点中的一个副本节点提供服务。建议采用什么方法与 Redis 建立连接,以有效利用集群中的所有副本节点进行读取操作。