0

I have a problem on connecting Spring Redis with the client. So I have a proxy with an hostname and there are 3 redis nodes but only one is available. I'm using the LettuceConnectionFactory to create the connection. When the application tries to connect to the client I got an exception:

Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis on unavailableIP:13376; nested exception is com.lambdaworks.redis.RedisConnectionException: Unable to connect to /unavailableIP:13376
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis on unavailableIP:13376; nested exception is com.lambdaworks.redis.RedisConnectionException: Unable to connect to /unavailableIP:13376
Caused by: org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis on unavailableIP:13376; nested exception is com.lambdaworks.redis.RedisConnectionException: Unable to connect to /unavailableIP:13376
Caused by: com.lambdaworks.redis.RedisConnectionException: Unable to connect to /unavailableIP:13376
Caused by: java.net.ConnectException: Connection refused: no further information: /unavailableIP:13376"}}

Instead.. if I try to connect from Redis Desktop Manager, it works..

Is there a way to apply a "retry" to get the available ip?

Fabrizio P
  • 241
  • 3
  • 13

1 Answers1

0

Using a DNS proxy with Java for HA can require some tweaks to your code/runtime. Java caches DNS responses for a certain time which can cause the Java code to resolve to the old IP address although your DNS would respond with an updated IP address. You should also note that, depending on the implementation of the availability checks, the backend takes some time until data is refreshed whereas a dropped connection in Lettuce is attempted to reconnect immediately.

I'd propose to refrain from using DNS-based balancers as you can only react to a dropped/timed out connection. Using more active approaches (like Redis Sentinel) are the better option.

You could try to configure Lettuce's DnsResolver with a custom DNS that resolves addresses every time you connect/reconnect.

See also:

mp911de
  • 17,546
  • 2
  • 55
  • 95