Redis的莴苣客户端-集群拓扑刷新选项不工作



我使用生菜客户端版本6.2.0连接到一个Redis集群(v6.2)与3主每个有一个副本。我正在尝试客户端在主服务器宕机后重新发现集群拓扑。下面是我的客户端代码:

List<RedisURI> redisURIs = new ArrayList<>();
redisURIs.add(RedisURI.create("redis://127.0.0.1:7000"));
redisURIs.add(RedisURI.create("redis://127.0.0.1:7001"));
redisURIs.add(RedisURI.create("redis://127.0.0.1:7002"));
redisURIs.add(RedisURI.create("redis://127.0.0.1:7003"));
redisURIs.add(RedisURI.create("redis://127.0.0.1:7004"));
redisURIs.add(RedisURI.create("redis://127.0.0.1:7005"));
ClusterTopologyRefreshOptions topologyRefreshOptions = ClusterTopologyRefreshOptions.builder()
.enableAllAdaptiveRefreshTriggers()
.refreshTriggersReconnectAttempts(1)
.enablePeriodicRefresh(Duration.ofSeconds(5))
.build();
ClusterClientOptions clientOptions = ClusterClientOptions.builder()
.autoReconnect(true).topologyRefreshOptions(topologyRefreshOptions).build();
ClientResources clientResources = ClientResources.builder().reconnectDelay(Delay.equalJitter()).build();
RedisClusterClient clusterClient = RedisClusterClient.create(clientResources, redisURIs);
clusterClient.setOptions(clientOptions);

问题是,尽管设置了enablePeriodicRefresh(Duration.ofSeconds(5)),刷新间隔仍然是60秒,而不是5秒。直到主机宕机1分钟后,客户端停止工作,即无法通过clusterClient发出incr操作,错误不断重复:

Jul 18, 2022 5:56:21 PM io.lettuce.core.protocol.ConnectionWatchdog lambda$run$4
WARNING: Cannot reconnect to [127.0.0.1:7000]: Connection refused: /127.0.0.1:7000

超时1分钟后,显示警告信息:

Jul 18, 2022 5:56:22 PM io.lettuce.core.cluster.topology.DefaultClusterTopologyRefresh lambda$openConnections$12
WARNING: Unable to connect to [127.0.0.1:7000]: Connection refused: /127.0.0.1:7000
Command timed out after 1 minute(s)

. .然后它就可以继续执行命令了。即使在此之后,它仍然显示警告消息:

Jul 18, 2022 5:56:27 PM io.lettuce.core.cluster.topology.DefaultClusterTopologyRefresh lambda$openConnections$12
WARNING: Unable to connect to [127.0.0.1:7000]: Connection refused: /127.0.0.1:7000

我在这里错过了什么?

enablePeriodicRefresh()设置在连接超时后生效。您不需要设置连接超时,但默认为60秒。调整连接超时将给你想要的结果。

) redisURIs.add交货(RedisURI.create("复述://127.0.0.1:7000/0 ?超时= 10 s"));

相关内容

  • 没有找到相关文章