Skip to content

Commit c2fd66f

Browse files
committed
Sentinel host is changed to be system independent
1 parent 3313195 commit c2fd66f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/redis/clients/jedis/JedisSentinelPool.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private HostAndPort initSentinels(Set<String> sentinels, final String masterName
136136
log.info("Trying to find master from available Sentinels...");
137137

138138
for (String sentinel : sentinels) {
139-
final HostAndPort hap = HostAndPort.parseString(sentinel);
139+
final HostAndPort hap = toHostAndPort(sentinel);
140140

141141
log.debug("Connecting to Sentinel {}", hap);
142142

@@ -185,7 +185,7 @@ private HostAndPort initSentinels(Set<String> sentinels, final String masterName
185185
log.info("Redis master running at " + master + ", starting Sentinel listeners...");
186186

187187
for (String sentinel : sentinels) {
188-
final HostAndPort hap = HostAndPort.parseString(sentinel);
188+
final HostAndPort hap = toHostAndPort(sentinel);
189189
MasterListener masterListener = new MasterListener(masterName, hap.getHost(), hap.getPort());
190190
// whether MasterListener threads are alive or not, process can be stopped
191191
masterListener.setDaemon(true);
@@ -199,7 +199,14 @@ private HostAndPort initSentinels(Set<String> sentinels, final String masterName
199199
private HostAndPort toHostAndPort(List<String> getMasterAddrByNameResult) {
200200
String host = getMasterAddrByNameResult.get(0);
201201
int port = Integer.parseInt(getMasterAddrByNameResult.get(1));
202+
return new HostAndPort(host, port);
203+
}
202204

205+
private HostAndPort toHostAndPort(String sentinel) {
206+
int lastColon = sentinel.lastIndexOf(":");
207+
if (lastColon == -1) throw new IllegalArgumentException(sentinel + " does not contain port.");
208+
String host = sentinel.substring(0, lastColon);
209+
int port = Integer.parseInt(sentinel.substring(lastColon + 1));
203210
return new HostAndPort(host, port);
204211
}
205212

0 commit comments

Comments
 (0)