|
|
@ -101,24 +101,39 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
|
|
|
|
|
|
|
|
|
|
|
|
this.sentinelResolver = resolverGroup.getResolver(getGroup().next());
|
|
|
|
this.sentinelResolver = resolverGroup.getResolver(getGroup().next());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean connected = false;
|
|
|
|
|
|
|
|
|
|
|
|
for (String address : cfg.getSentinelAddresses()) {
|
|
|
|
for (String address : cfg.getSentinelAddresses()) {
|
|
|
|
RedisURI addr = new RedisURI(address);
|
|
|
|
RedisURI addr = new RedisURI(address);
|
|
|
|
RedisClient client = createClient(NodeType.SENTINEL, addr, this.config.getConnectTimeout(), this.config.getTimeout(), null);
|
|
|
|
RedisClient client = createClient(NodeType.SENTINEL, addr, this.config.getConnectTimeout(), this.config.getTimeout(), null);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
RedisConnection c = client.connect();
|
|
|
|
RedisConnection c = client.connect();
|
|
|
|
|
|
|
|
connected = true;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
c.sync(RedisCommands.PING);
|
|
|
|
c.sync(RedisCommands.PING);
|
|
|
|
scheme = addr.getScheme();
|
|
|
|
scheme = addr.getScheme();
|
|
|
|
} catch (RedisAuthRequiredException e) {
|
|
|
|
} catch (RedisAuthRequiredException e) {
|
|
|
|
usePassword = true;
|
|
|
|
usePassword = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
client.shutdown();
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
} catch (RedisConnectionException e) {
|
|
|
|
|
|
|
|
log.warn("Can't connect to sentinel server. {}", e.getMessage());
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// skip
|
|
|
|
// skip
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
client.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!connected) {
|
|
|
|
|
|
|
|
stopThreads();
|
|
|
|
|
|
|
|
StringBuilder list = new StringBuilder();
|
|
|
|
|
|
|
|
for (String address : cfg.getSentinelAddresses()) {
|
|
|
|
|
|
|
|
list.append(address).append(", ");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new RedisConnectionException("Unable to connect to Redis sentinel servers: " + list);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (String address : cfg.getSentinelAddresses()) {
|
|
|
|
for (String address : cfg.getSentinelAddresses()) {
|
|
|
|
RedisURI addr = new RedisURI(address);
|
|
|
|
RedisURI addr = new RedisURI(address);
|
|
|
|
if (NetUtil.createByteArrayFromIpAddressString(addr.getHost()) == null && !addr.getHost().equals("localhost")) {
|
|
|
|
if (NetUtil.createByteArrayFromIpAddressString(addr.getHost()) == null && !addr.getHost().equals("localhost")) {
|
|
|
@ -190,7 +205,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} catch (RedisConnectionException e) {
|
|
|
|
} catch (RedisConnectionException e) {
|
|
|
|
log.warn("Can't connect to sentinel server. {}", e.getMessage());
|
|
|
|
// skip
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
client.shutdownAsync();
|
|
|
|
client.shutdownAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|