Skip to content

Commit

Permalink
Configure a Sentinel Connection when initialising the Sentinel pool (#…
Browse files Browse the repository at this point in the history
…1943)

This commit attempts to solve #1487 and #1636.

This PR adds a constructor to JedisSentinelPool to configure a Sentinel connection with respective timeout settings and a password. Supporting constructors have also been added to BinaryJedis and Jedis classes.
  • Loading branch information
Karl Tinawi authored and sazzad16 committed Nov 26, 2019
1 parent 832091e commit 6b86fe7
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/main/java/redis/clients/jedis/JedisSentinelPool.java
Expand Up @@ -17,15 +17,17 @@ public class JedisSentinelPool extends JedisPoolAbstract {

protected GenericObjectPoolConfig poolConfig;

protected int connectionTimeout = Protocol.DEFAULT_TIMEOUT;
protected int soTimeout = Protocol.DEFAULT_TIMEOUT;

protected int connectionTimeout;
protected int soTimeout;
protected String password;

protected int database = Protocol.DEFAULT_DATABASE;

protected int database;
protected String clientName;

protected int sentinelConnectionTimeout;
protected int sentinelSoTimeout;
protected String sentinelPassword;
protected String sentinelClientName;

protected Set<MasterListener> masterListeners = new HashSet<MasterListener>();

protected Logger log = LoggerFactory.getLogger(getClass().getName());
Expand Down Expand Up @@ -86,12 +88,26 @@ public JedisSentinelPool(String masterName, Set<String> sentinels,
public JedisSentinelPool(String masterName, Set<String> sentinels,
final GenericObjectPoolConfig poolConfig, final int connectionTimeout, final int soTimeout,
final String password, final int database, final String clientName) {
this(masterName, sentinels, poolConfig, connectionTimeout, soTimeout, password, database, clientName,
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null, null);
}

public JedisSentinelPool(String masterName, Set<String> sentinels,
final GenericObjectPoolConfig poolConfig, final int connectionTimeout, final int soTimeout,
final String password, final int database, final String clientName,
final int sentinelConnectionTimeout, final int sentinelSoTimeout, final String sentinelPassword,
final String sentinelClientName) {

this.poolConfig = poolConfig;
this.connectionTimeout = connectionTimeout;
this.soTimeout = soTimeout;
this.password = password;
this.database = database;
this.clientName = clientName;
this.sentinelConnectionTimeout = sentinelConnectionTimeout;
this.sentinelSoTimeout = sentinelSoTimeout;
this.sentinelPassword = sentinelPassword;
this.sentinelClientName = sentinelClientName;

HostAndPort master = initSentinels(sentinels, masterName);
initPool(master);
Expand Down Expand Up @@ -146,7 +162,13 @@ private HostAndPort initSentinels(Set<String> sentinels, final String masterName

Jedis jedis = null;
try {
jedis = new Jedis(hap);
jedis = new Jedis(hap.getHost(), hap.getPort(), sentinelConnectionTimeout, sentinelSoTimeout);
if (sentinelPassword != null) {
jedis.auth(sentinelPassword);
}
if (sentinelClientName != null) {
jedis.clientSetname(sentinelClientName);
}

List<String> masterAddr = jedis.sentinelGetMasterAddrByName(masterName);

Expand Down Expand Up @@ -352,4 +374,4 @@ public void shutdown() {
}
}
}
}
}

0 comments on commit 6b86fe7

Please sign in to comment.