How to set TTL for DNS cache in Lettuce/Redis Connection in Springboot 3

1.1k Views Asked by At

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

0

There are 0 best solutions below