Closed tonyghita closed 3 years ago
Same problem here. We use spring boot with spring-boot-starter-data-redis
application.yml:
spring:
redis:
sentinel:
master: webrio-integration-master
nodes: localhost:26379
password: secret
Log:
03-Aug-2017 14:51:46 [localhost-startStop-1] INFO : redis.clients.jedis.JedisSentinelPool:136 - Trying to find master from available Sentinels...
03-Aug-2017 14:51:46 [localhost-startStop-1] DEBUG : redis.clients.jedis.JedisSentinelPool:141 - Connecting to Sentinel 10.183.160.202:26379
03-Aug-2017 14:19:40 [localhost-startStop-1] WARN : redis.clients.jedis.JedisSentinelPool:164 - Cannot get master address from sentinel running @ 10.183.160.202:26379.
Reason: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused). Trying next one.
...
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: All sentinels down, cannot determine where is webrio-integration-master master is running...
at redis.clients.jedis.JedisSentinelPool.initSentinels(JedisSentinelPool.java:180)
at redis.clients.jedis.JedisSentinelPool.<init>(JedisSentinelPool.java:95)
at redis.clients.jedis.JedisSentinelPool.<init>(JedisSentinelPool.java:76)
Changing to spring.redis.sentinel.nodes: 127.0.0.1:26379
doesn't help, as per original post.
A quick hack around this is to use 127.0.1.1 instead which shouldn't trigger the getLocalHostQuietly
function.
For those trying this on OSX https://stackoverflow.com/a/56082275/6190803
One of possible workarounds is to set it explicitly
HostAndPort.setLocalhost("127.0.0.1");
then jedis will not try to resolve it.
From Jedis 3.6.0 (due to #2445), there are two new constructors with Set<HostAndPort> sentinels
param. These constructors will not convert the hosts and treat the hosts as they are provided.
Expected behavior
I have my Jedis client configured to connect to
localhost
. I expect the connection to be made to the localhost via loopback.Actual behavior
As of the changes in https://github.com/xetorthio/jedis/pull/1342, when specifying a
localhost
address, it now resolves to my machine's network ip address.This makes it impossible to connect to a
redis-sentinel
on localhost because the sentinel only allows connections from loopback on more recent versions of Redis.Steps to reproduce:
'localhost'
'localhost'
resolved to an external ip (i.e.10.1.10.254
).I think the new behavior in
getLocalHostQuietly()
introduces system-dependent behavior viaInetAddress.getLocalHost().getHostAddress()
, which does not seem to be the intent of the code.Redis / Jedis Configuration
Jedis version:
2.9.x (since https://github.com/xetorthio/jedis/pull/1342)
Redis version:
3.2.2
Java version: