RedisClient fails to reconnect #2421
Replies: 3 comments 1 reply
-
Sounds pretty much like a DNS caching issue. Please ensure the resolved IP address matches the refreshed/restarted Redis container. You can check this by enabling debug logging. |
Beta Was this translation helpful? Give feedback.
-
Hi @mp911de - Could you please help me to resolve this discussion? |
Beta Was this translation helpful? Give feedback.
-
Hello @mp911de and @AbhishekS2304, were you able to handle this problem? I have the same behavior described by Abhishek:
And with debug logging I also confirmed the lettuce client is trying to reconnect to the old IP address of redis service. Additional information
spring:
data:
redis:
cluster:
nodes:
- <redis_service_name>:6379 It was possible to confirm in debug that the dnscache used by lettuce is I was able to customize the @Bean
ClientResourcesBuilderCustomizer customizer()
{
return clientResourcesBuilder -> clientResourcesBuilder.addressResolverGroup(new DnsAddressResolverGroup(
new DnsNameResolverBuilder().channelType(Transports.datagramChannelClass())
.socketChannelType(Transports.socketChannelClass().asSubclass(SocketChannel.class))
.cnameCache(new DefaultDnsCnameCache())
.resolveCache(new DefaultDnsCache(0, 1, 0))));
} And this solves the issue because now the maxTtl is 1 second, and after this 1 second, the cached IP from the old redis service is cleared and the DNS is resolved again. Is there another way of configuring this maxTtl for DefaultDnsCache? What is the recommended approach? |
Beta Was this translation helpful? Give feedback.
-
I have a redis client application (service A) (using lettuce 6.2.1.RELEASE) which connects to redis container and subscribes a channel. When the redis container is up, service 'A' (running as a container) starts and connects with redis. Everything is fine until now.
When the redis container restarts. Service 'A' goes on reconnecting forever but couldn't reconnect. To restore the connection, I always have to restart service 'A' after the redis container is up. Is there a way to reconnect without restarting service 'A'?
RedisURI REDIS_URI= RedisURI.Builder.redis("redis", 6379).withAuthentication("redisUsername", "redisPassword").build()
ClientResources clientResources = DefaultClientResources.create();
RedisClient redisClient = RedisClient.create(clientResources, REDIS_URI); redisClient.setOptions(ClientOptions.builder().autoReconnect(true).pingBeforeActivateConnection(true).build());
redisClient.connectPubSub();
Beta Was this translation helpful? Give feedback.
All reactions