我正在使用Lettuce客户端6.2.0版连接到一个Redis集群(6.2版),该集群有3个主节点,每个主节点有1个副本。我正在尝试让客户端在一个主节点崩溃后重新发现集群拓扑结构。下面是我的客户端代码:
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
我错过了什么?
1条答案
按热度按时间qxgroojn1#
enablePeriodicRefresh()设置在连接超时后起作用。您不设置连接超时,但它默认为60秒。调整连接超时将给予您想要的结果。
例如:添加(127.0.0.1:7000/0?timeout=10s;