-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Allowed connect to redis-master with ssl. #2024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,20 @@ | |
import redis.clients.jedis.exceptions.JedisConnectionException; | ||
import redis.clients.jedis.exceptions.JedisException; | ||
|
||
import javax.net.ssl.HostnameVerifier; | ||
import javax.net.ssl.SSLParameters; | ||
import javax.net.ssl.SSLSocketFactory; | ||
|
||
public class JedisSentinelPool extends JedisPoolAbstract { | ||
|
||
protected GenericObjectPoolConfig poolConfig; | ||
|
||
protected int connectionTimeout = Protocol.DEFAULT_TIMEOUT; | ||
protected int soTimeout = Protocol.DEFAULT_TIMEOUT; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An empty line would make code more readable. |
||
protected Boolean isRedisSslEnabled; | ||
protected SSLSocketFactory sslSocketFactory; | ||
protected SSLParameters sslParameters; | ||
protected HostnameVerifier hostnameVerifier; | ||
protected String password; | ||
|
||
protected int database = Protocol.DEFAULT_DATABASE; | ||
|
@@ -41,10 +48,24 @@ public JedisSentinelPool(String masterName, Set<String> sentinels, | |
Protocol.DEFAULT_DATABASE); | ||
} | ||
|
||
public JedisSentinelPool(String masterName, Set<String> sentinels, | ||
final GenericObjectPoolConfig poolConfig, final Boolean isRedisSslEnabled) { | ||
this(masterName, sentinels, poolConfig, Protocol.DEFAULT_TIMEOUT, null, | ||
Protocol.DEFAULT_DATABASE, isRedisSslEnabled); | ||
} | ||
|
||
public JedisSentinelPool(String masterName, Set<String> sentinels) { | ||
this(masterName, sentinels, new GenericObjectPoolConfig(), Protocol.DEFAULT_TIMEOUT, null, | ||
Protocol.DEFAULT_DATABASE); | ||
} | ||
public JedisSentinelPool(String masterName, Set<String> sentinels, final Boolean isRedisSslEnabled) { | ||
this(masterName, sentinels, new GenericObjectPoolConfig(), Protocol.DEFAULT_TIMEOUT, null, | ||
Protocol.DEFAULT_DATABASE, isRedisSslEnabled); | ||
} | ||
|
||
public JedisSentinelPool(String masterName, Set<String> sentinels, String password, final Boolean isRedisSslEnabled) { | ||
this(masterName, sentinels, new GenericObjectPoolConfig(), Protocol.DEFAULT_TIMEOUT, password); | ||
} | ||
|
||
public JedisSentinelPool(String masterName, Set<String> sentinels, String password) { | ||
this(masterName, sentinels, new GenericObjectPoolConfig(), Protocol.DEFAULT_TIMEOUT, password); | ||
|
@@ -68,30 +89,57 @@ public JedisSentinelPool(String masterName, Set<String> sentinels, | |
public JedisSentinelPool(String masterName, Set<String> sentinels, | ||
final GenericObjectPoolConfig poolConfig, int timeout, final String password, | ||
final int database) { | ||
this(masterName, sentinels, poolConfig, timeout, timeout, password, database); | ||
this(masterName, sentinels, poolConfig, timeout, timeout, password, database, false); | ||
} | ||
|
||
public JedisSentinelPool(String masterName, Set<String> sentinels, | ||
final GenericObjectPoolConfig poolConfig, int timeout, final String password, | ||
final int database, final Boolean isRedisSslEnabled) { | ||
this(masterName, sentinels, poolConfig, timeout, timeout, password, database, isRedisSslEnabled); | ||
} | ||
|
||
public JedisSentinelPool(String masterName, Set<String> sentinels, | ||
final GenericObjectPoolConfig poolConfig, int timeout, final String password, | ||
final int database, final String clientName) { | ||
this(masterName, sentinels, poolConfig, timeout, timeout, password, database, clientName); | ||
this(masterName, sentinels, poolConfig, timeout, timeout, password, database, clientName, false, | ||
null, null, null); | ||
} | ||
|
||
public JedisSentinelPool(String masterName, Set<String> sentinels, | ||
final GenericObjectPoolConfig poolConfig, int timeout, final String password, | ||
final int database, final String clientName, final Boolean isRedisSslEnabled) { | ||
this(masterName, sentinels, poolConfig, timeout, timeout, password, database, clientName, isRedisSslEnabled, | ||
null, null, null); | ||
} | ||
|
||
public JedisSentinelPool(String masterName, Set<String> sentinels, | ||
final GenericObjectPoolConfig poolConfig, final int timeout, final int soTimeout, | ||
final String password, final int database) { | ||
this(masterName, sentinels, poolConfig, timeout, soTimeout, password, database, null, false, | ||
null, null, null); | ||
} | ||
|
||
public JedisSentinelPool(String masterName, Set<String> sentinels, | ||
final GenericObjectPoolConfig poolConfig, final int timeout, final int soTimeout, | ||
final String password, final int database) { | ||
this(masterName, sentinels, poolConfig, timeout, soTimeout, password, database, null); | ||
final String password, final int database, final Boolean isRedisSslEnabled) { | ||
this(masterName, sentinels, poolConfig, timeout, soTimeout, password, database, null, isRedisSslEnabled, | ||
null, 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 String password, final int database, final String clientName, final Boolean isRedisSslEnabled, | ||
final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) { | ||
this.poolConfig = poolConfig; | ||
this.connectionTimeout = connectionTimeout; | ||
this.soTimeout = soTimeout; | ||
this.password = password; | ||
this.database = database; | ||
this.clientName = clientName; | ||
this.isRedisSslEnabled = isRedisSslEnabled; | ||
this.sslSocketFactory = sslSocketFactory; | ||
this.sslParameters = sslParameters; | ||
this.hostnameVerifier = hostnameVerifier; | ||
|
||
HostAndPort master = initSentinels(sentinels, masterName); | ||
initPool(master); | ||
|
@@ -116,7 +164,8 @@ private void initPool(HostAndPort master) { | |
currentHostMaster = master; | ||
if (factory == null) { | ||
factory = new JedisFactory(master.getHost(), master.getPort(), connectionTimeout, | ||
gkorland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
soTimeout, password, database, clientName); | ||
soTimeout, password, database, clientName, isRedisSslEnabled, | ||
sslSocketFactory, sslParameters, hostnameVerifier); | ||
initPool(poolConfig, factory); | ||
} else { | ||
factory.setHostAndPort(currentHostMaster); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this constructor? Isn't following constructor enough?
I'm asking this because JedisFactory is kept to have fewest constructors.