Skip to content

Commit f94b6e5

Browse files
committed
JedisClientConfig extends JedisSocketConfig
1 parent ac0c9e3 commit f94b6e5

11 files changed

+198
-86
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ public BinaryJedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeo
109109
this.maxAttempts = maxAttempts;
110110
}
111111

112-
public BinaryJedisCluster(Set<HostAndPort> jedisClusterNode, JedisSocketConfig socketConfig,
113-
JedisClientConfig clientConfig, int maxAttempts, GenericObjectPoolConfig poolConfig) {
114-
this.connectionHandler = new JedisSlotBasedConnectionHandler(jedisClusterNode, poolConfig,
115-
socketConfig, clientConfig);
112+
public BinaryJedisCluster(Set<HostAndPort> jedisClusterNode, JedisClientConfig clientConfig,
113+
int maxAttempts, GenericObjectPoolConfig poolConfig) {
114+
this.connectionHandler = new JedisSlotBasedConnectionHandler(jedisClusterNode, poolConfig, clientConfig);
116115
this.maxAttempts = maxAttempts;
117116
}
118117

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

Lines changed: 134 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,59 @@
11
package redis.clients.jedis;
22

3+
import javax.net.ssl.HostnameVerifier;
4+
import javax.net.ssl.SSLParameters;
5+
import javax.net.ssl.SSLSocketFactory;
6+
37
public class DefaultJedisClientConfig implements JedisClientConfig {
48

9+
private final int connectionTimeout;
10+
private final int soTimeout;
511
private final int infiniteSoTimeout;
12+
613
private final String user;
714
private final String password;
815
private final int database;
916
private final String clientName;
1017

11-
private DefaultJedisClientConfig(int infiniteSoTimeout,
12-
String user, String password, int database, String clientName) {
18+
private final boolean ssl;
19+
private final SSLSocketFactory sslSocketFactory;
20+
private final SSLParameters sslParameters;
21+
private final HostnameVerifier hostnameVerifier;
22+
23+
private final HostAndPortMapper hostAndPortMapper;
24+
25+
private DefaultJedisClientConfig(int connectionTimeout, int soTimeout, int infiniteSoTimeout,
26+
String user, String password, int database, String clientName,
27+
boolean ssl, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
28+
HostnameVerifier hostnameVerifier, HostAndPortMapper hostAndPortMapper) {
29+
this.connectionTimeout = connectionTimeout;
30+
this.soTimeout = soTimeout;
1331
this.infiniteSoTimeout = infiniteSoTimeout;
1432
this.user = user;
1533
this.password = password;
1634
this.database = database;
1735
this.clientName = clientName;
36+
this.ssl = ssl;
37+
this.sslSocketFactory = sslSocketFactory;
38+
this.sslParameters = sslParameters;
39+
this.hostnameVerifier = hostnameVerifier;
40+
this.hostAndPortMapper = hostAndPortMapper;
1841
}
1942

2043
public static Builder builder() {
2144
return new Builder();
2245
}
2346

47+
@Override
48+
public int getConnectionTimeout() {
49+
return connectionTimeout;
50+
}
51+
52+
@Override
53+
public int getSoTimeout() {
54+
return soTimeout;
55+
}
56+
2457
@Override
2558
public int getInfiniteSoTimeout() {
2659
return infiniteSoTimeout;
@@ -46,20 +79,66 @@ public String getClientName() {
4679
return clientName;
4780
}
4881

82+
@Override
83+
public boolean isSSL() {
84+
return ssl;
85+
}
86+
87+
@Override
88+
public SSLSocketFactory getSSLSocketFactory() {
89+
return sslSocketFactory;
90+
}
91+
92+
@Override
93+
public SSLParameters getSSLParameters() {
94+
return sslParameters;
95+
}
96+
97+
@Override
98+
public HostnameVerifier getHostnameVerifier() {
99+
return hostnameVerifier;
100+
}
101+
102+
@Override
103+
public HostAndPortMapper getHostAndPortMapper() {
104+
return hostAndPortMapper;
105+
}
106+
49107
public static class Builder {
50108

109+
private int connectionTimeout = Protocol.DEFAULT_TIMEOUT;
110+
private int soTimeout = Protocol.DEFAULT_TIMEOUT;
51111
private int infiniteSoTimeout = 0;
52112

53113
private String user = null;
54114
private String password = null;
55115
private int databse = Protocol.DEFAULT_DATABASE;
56116
private String clinetName = null;
57117

118+
private boolean ssl = false;
119+
private SSLSocketFactory sslSocketFactory = null;
120+
private SSLParameters sslParameters = null;
121+
private HostnameVerifier hostnameVerifier = null;
122+
123+
private HostAndPortMapper hostAndPortMapper = null;
124+
58125
private Builder() {
59126
}
60127

61128
public DefaultJedisClientConfig build() {
62-
return new DefaultJedisClientConfig(infiniteSoTimeout, user, password, databse, clinetName);
129+
return new DefaultJedisClientConfig(connectionTimeout, soTimeout, infiniteSoTimeout,
130+
user, password, databse, clinetName,
131+
ssl, sslSocketFactory, sslParameters, hostnameVerifier, hostAndPortMapper);
132+
}
133+
134+
public Builder withConnectionTimeout(int connectionTimeout) {
135+
this.connectionTimeout = connectionTimeout;
136+
return this;
137+
}
138+
139+
public Builder withSoTimeout(int soTimeout) {
140+
this.soTimeout = soTimeout;
141+
return this;
63142
}
64143

65144
public Builder withInfiniteSoTimeout(int infiniteSoTimeout) {
@@ -87,6 +166,39 @@ public Builder withClinetName(String clinetName) {
87166
return this;
88167
}
89168

169+
public Builder withSsl(boolean ssl) {
170+
this.ssl = ssl;
171+
return this;
172+
}
173+
174+
public Builder withSslSocketFactory(SSLSocketFactory sslSocketFactory) {
175+
this.sslSocketFactory = sslSocketFactory;
176+
return this;
177+
}
178+
179+
public Builder withSslParameters(SSLParameters sslParameters) {
180+
this.sslParameters = sslParameters;
181+
return this;
182+
}
183+
184+
public Builder withHostnameVerifier(HostnameVerifier hostnameVerifier) {
185+
this.hostnameVerifier = hostnameVerifier;
186+
return this;
187+
}
188+
189+
public Builder withHostAndPortMapper(HostAndPortMapper hostAndPortMapper) {
190+
this.hostAndPortMapper = hostAndPortMapper;
191+
return this;
192+
}
193+
194+
public int getConnectionTimeout() {
195+
return connectionTimeout;
196+
}
197+
198+
public int getSoTimeout() {
199+
return soTimeout;
200+
}
201+
90202
public int getInfiniteSoTimeout() {
91203
return infiniteSoTimeout;
92204
}
@@ -107,5 +219,24 @@ public String getClinetName() {
107219
return clinetName;
108220
}
109221

222+
public boolean isSsl() {
223+
return ssl;
224+
}
225+
226+
public SSLSocketFactory getSslSocketFactory() {
227+
return sslSocketFactory;
228+
}
229+
230+
public SSLParameters getSslParameters() {
231+
return sslParameters;
232+
}
233+
234+
public HostnameVerifier getHostnameVerifier() {
235+
return hostnameVerifier;
236+
}
237+
238+
public HostAndPortMapper getHostAndPortMapper() {
239+
return hostAndPortMapper;
240+
}
110241
}
111242
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package redis.clients.jedis;
22

3-
public interface JedisClientConfig {
3+
public interface JedisClientConfig extends JedisSocketConfig {
44

55
int getInfiniteSoTimeout();
66

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ public JedisCluster(HostAndPort node, int connectionTimeout, int soTimeout,
9999
ssl, sslSocketFactory, sslParameters, hostnameVerifier, hostAndPortMap);
100100
}
101101

102-
public JedisCluster(HostAndPort node, final JedisSocketConfig socketConfig,
103-
final JedisClientConfig clientConfig, int maxAttempts, final GenericObjectPoolConfig poolConfig) {
104-
this(Collections.singleton(node), socketConfig, clientConfig, maxAttempts, poolConfig);
102+
public JedisCluster(HostAndPort node, final JedisClientConfig clientConfig, int maxAttempts, final GenericObjectPoolConfig poolConfig) {
103+
this(Collections.singleton(node), clientConfig, maxAttempts, poolConfig);
105104
}
106105

107106
public JedisCluster(Set<HostAndPort> nodes) {
@@ -198,9 +197,9 @@ public JedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout, in
198197
clientName, poolConfig, ssl, sslSocketFactory, sslParameters, hostnameVerifier, hostAndPortMap);
199198
}
200199

201-
public JedisCluster(Set<HostAndPort> nodes, final JedisSocketConfig socketConfig,
202-
final JedisClientConfig clientConfig, int maxAttempts, final GenericObjectPoolConfig poolConfig) {
203-
super(nodes, socketConfig, clientConfig, maxAttempts, poolConfig);
200+
public JedisCluster(Set<HostAndPort> nodes, final JedisClientConfig clientConfig, int maxAttempts,
201+
final GenericObjectPoolConfig poolConfig) {
202+
super(nodes, clientConfig, maxAttempts, poolConfig);
204203
}
205204

206205
@Override

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,30 @@ public JedisClusterConnectionHandler(Set<HostAndPort> nodes, final GenericObject
5656
boolean ssl, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
5757
HostnameVerifier hostnameVerifier, JedisClusterHostAndPortMap portMap) {
5858
this(nodes,
59-
DefaultJedisSocketConfig.builder().withConnectionTimeout(connectionTimeout).withSoTimeout(soTimeout)
59+
DefaultJedisClientConfig.builder().withConnectionTimeout(connectionTimeout)
60+
.withSoTimeout(soTimeout).withInfiniteSoTimeout(infiniteSoTimeout)
61+
.withUser(user).withPassword(password).withClinetName(clientName)
6062
.withSsl(ssl).withSslSocketFactory(sslSocketFactory).withSslParameters(sslParameters)
6163
.withHostnameVerifier(hostnameVerifier).build(),
6264
poolConfig,
63-
DefaultJedisSocketConfig.builder().withConnectionTimeout(connectionTimeout).withSoTimeout(soTimeout)
65+
DefaultJedisClientConfig.builder().withConnectionTimeout(connectionTimeout)
66+
.withSoTimeout(soTimeout).withInfiniteSoTimeout(infiniteSoTimeout)
67+
.withUser(user).withPassword(password).withClinetName(clientName)
6468
.withSsl(ssl).withSslSocketFactory(sslSocketFactory).withSslParameters(sslParameters)
65-
.withHostnameVerifier(hostnameVerifier).withHostAndPortMapper(portMap).build(),
66-
infiniteSoTimeout, user, password, clientName);
69+
.withHostnameVerifier(hostnameVerifier).withHostAndPortMapper(portMap).build());
6770
}
6871

6972
@Deprecated
70-
public JedisClusterConnectionHandler(Set<HostAndPort> nodes, final JedisSocketConfig seedNodesSocketConfig,
71-
final GenericObjectPoolConfig poolConfig, final JedisSocketConfig clusterNodesSocketConfig,
72-
int infiniteSoTimeout, String user, String password, String clientName) {
73-
final JedisClientConfig clientConfig = DefaultJedisClientConfig.builder().withInfiniteSoTimeout(infiniteSoTimeout)
74-
.withUser(user).withPassword(password).withClinetName(clientName).build();
75-
this.cache = new JedisClusterInfoCache(poolConfig, clusterNodesSocketConfig, clientConfig);
76-
initializeSlotsCache(nodes, seedNodesSocketConfig, clientConfig);
73+
public JedisClusterConnectionHandler(Set<HostAndPort> nodes, final JedisClientConfig seedNodesClientConfig,
74+
final GenericObjectPoolConfig poolConfig, final JedisClientConfig clusterNodesClientConfig) {
75+
this.cache = new JedisClusterInfoCache(poolConfig, clusterNodesClientConfig);
76+
initializeSlotsCache(nodes, seedNodesClientConfig);
7777
}
7878

79-
public JedisClusterConnectionHandler(Set<HostAndPort> nodes, final GenericObjectPoolConfig poolConfig,
80-
final JedisSocketConfig socketConfig, final JedisClientConfig clientConfig) {
81-
this.cache = new JedisClusterInfoCache(poolConfig, socketConfig, clientConfig);
82-
initializeSlotsCache(nodes, socketConfig, clientConfig);
79+
public JedisClusterConnectionHandler(Set<HostAndPort> nodes,
80+
final GenericObjectPoolConfig poolConfig, final JedisClientConfig clientConfig) {
81+
this.cache = new JedisClusterInfoCache(poolConfig, clientConfig);
82+
initializeSlotsCache(nodes, clientConfig);
8383
}
8484

8585
abstract Jedis getConnection();
@@ -94,11 +94,10 @@ public Map<String, JedisPool> getNodes() {
9494
return cache.getNodes();
9595
}
9696

97-
private void initializeSlotsCache(Set<HostAndPort> startNodes, JedisSocketConfig socketConfig,
98-
JedisClientConfig clientConfig) {
97+
private void initializeSlotsCache(Set<HostAndPort> startNodes, JedisClientConfig clientConfig) {
9998

10099
for (HostAndPort hostAndPort : startNodes) {
101-
try (Jedis jedis = new Jedis(hostAndPort, socketConfig, clientConfig.getInfiniteSoTimeout())) {
100+
try (Jedis jedis = new Jedis(hostAndPort, (JedisSocketConfig) clientConfig, clientConfig.getInfiniteSoTimeout())) {
102101
if (clientConfig.getUser() != null) {
103102
jedis.auth(clientConfig.getUser(), clientConfig.getPassword());
104103
} else if (clientConfig.getPassword() != null) {

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class JedisClusterInfoCache {
2727
private volatile boolean rediscovering;
2828

2929
private final GenericObjectPoolConfig poolConfig;
30-
private final JedisSocketConfig socketConfig;
3130
private final JedisClientConfig clientConfig;
3231

3332
private static final int MASTER_NODE_INDEX = 2;
@@ -103,19 +102,17 @@ public JedisClusterInfoCache(final GenericObjectPoolConfig poolConfig,
103102
SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
104103
HostnameVerifier hostnameVerifier, HostAndPortMapper hostAndPortMap) {
105104
this(poolConfig,
106-
DefaultJedisSocketConfig.builder().withConnectionTimeout(connectionTimeout)
107-
.withSoTimeout(soTimeout).withSsl(ssl).withSslSocketFactory(sslSocketFactory)
105+
DefaultJedisClientConfig.builder().withConnectionTimeout(connectionTimeout)
106+
.withSoTimeout(soTimeout).withInfiniteSoTimeout(infiniteSoTimeout)
107+
.withUser(user).withPassword(password).withClinetName(clientName)
108+
.withSsl(ssl).withSslSocketFactory(sslSocketFactory)
108109
.withSslParameters(sslParameters) .withHostnameVerifier(hostnameVerifier)
109-
.withHostAndPortMapper(hostAndPortMap).build(),
110-
DefaultJedisClientConfig.builder().withInfiniteSoTimeout(infiniteSoTimeout)
111-
.withUser(user).withPassword(password).withClinetName(clientName).build()
110+
.withHostAndPortMapper(hostAndPortMap).build()
112111
);
113112
}
114113

115-
public JedisClusterInfoCache(final GenericObjectPoolConfig poolConfig,
116-
final JedisSocketConfig socketConfig, final JedisClientConfig clientConfig) {
114+
public JedisClusterInfoCache(final GenericObjectPoolConfig poolConfig, final JedisClientConfig clientConfig) {
117115
this.poolConfig = poolConfig;
118-
this.socketConfig = socketConfig;
119116
this.clientConfig = clientConfig;
120117
}
121118

@@ -235,7 +232,7 @@ public JedisPool setupNodeIfNotExist(final HostAndPort node) {
235232
JedisPool existingPool = nodes.get(nodeKey);
236233
if (existingPool != null) return existingPool;
237234

238-
JedisPool nodePool = new JedisPool(poolConfig, node, socketConfig, clientConfig);
235+
JedisPool nodePool = new JedisPool(poolConfig, node, clientConfig);
239236
nodes.put(nodeKey, nodePool);
240237
return nodePool;
241238
} finally {

0 commit comments

Comments
 (0)