Spring数据redis无法连接到Redis DNS代理

问题描述 投票:0回答:1

我在将Spring Redis与客户端连接时遇到问题。所以我有一个带有主机名的代理,有3个redis节点,但只有一个可用。我正在使用LettuceConnectionFactory来创建连接。当应用程序尝试连接到客户端时,我得到一个异常:

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"}}

相反..如果我尝试从Redis桌面管理器连接,它的工作..

有没有办法应用“重试”来获得可用的IP?

java spring proxy redis connection
1个回答
0
投票

使用带有Java for HA的DNS代理可能需要对代码/运行时进行一些调整。 Java会将DNS响应缓存一段时间,这会导致Java代码解析为旧的IP地址,尽管您的DNS会使用更新的IP地址进行响应。您还应注意,根据可用性检查的实现,后端需要一些时间才能刷新数据,而Lettuce中的连接断开尝试立即重新连接。

我建议不要使用基于DNS的平衡器,因为您只能对丢弃/超时连接做出反应。使用更积极的方法(如Redis Sentinel)是更好的选择。

您可以尝试使用自定义DNS配置Lettuce的DnsResolver,该DNS可在每次连接/重新连接时解析地址。

也可以看看:

© www.soinside.com 2019 - 2024. All rights reserved.