1

Our production system experienced a Redis connection timeout due to an outdated IP address returned by DNS lookup after Amazon AWS performed a system update on Elastic Cache cluster. To prevent this issue from happening again in the future and to increase the resilience of the Spring Boot application, I am exploring potential solutions.

One approach I considered was setting a shorter TTL for the DNS resolver cache. However, when attempting to implement this using a sample implementation below, I discovered that the dnsResolver method is not available in Lettuce 6.1, which I am currently using.

@Bean
public DnsResolver dnsResolver() {
    DefaultDnsResolver resolver = new DefaultDnsResolver();
    resolver.setCacheTimeToLive(Duration.ofSeconds(10));
    return resolver;
}

LettuceClientConfiguration lettuceConfig = LettuceClientConfiguration.builder()
            .dnsResolver(dnsResolver)
            .build()

I also considered forcing a one-time DNS cache refresh in the event of a connection timeout to reduce the frequency of DNS lookups that might affect performance.

I would appreciate any guidance on the most optimal approach for resolving this issue and a reference implementation for Spring Boot 3 using Lettuce 6.1, as the previous code snippet did not compile for me.

I tried the snippet above but it does not compile.

FYI: Springboot pulls transitive dependency lettuce-core:6.2.2.RELEASE

Tiger
  • 11
  • 3
  • Does this answer your question? [Changing JAVA DNS Cache settings](https://stackoverflow.com/questions/42976379/changing-java-dns-cache-settings) – Chin Huang Mar 06 '23 at 19:17
  • Thanks, @ChinHuang I have come across this approach, and it seems quite intrusive. I was hoping to find a less intrusive alternative where I could confine the modification to the lettuce connection factory. – Tiger Mar 09 '23 at 03:21

0 Answers0