20
20
/**
21
21
* PoolableObjectFactory custom impl.
22
22
*/
23
- class JedisFactory implements PooledObjectFactory <Jedis > {
23
+ public class JedisFactory implements PooledObjectFactory <Jedis > {
24
24
25
25
private static final Logger logger = LoggerFactory .getLogger (JedisFactory .class );
26
26
27
27
private final AtomicReference <HostAndPort > hostAndPort = new AtomicReference <>();
28
28
29
29
private final JedisClientConfig config ;
30
30
31
- JedisFactory (final String host , final int port , final int connectionTimeout ,
31
+ protected JedisFactory (final String host , final int port , final int connectionTimeout ,
32
32
final int soTimeout , final String password , final int database , final String clientName ) {
33
33
this (host , port , connectionTimeout , soTimeout , password , database , clientName , false , null , null , null );
34
34
}
35
35
36
- JedisFactory (final String host , final int port , final int connectionTimeout ,
36
+ protected JedisFactory (final String host , final int port , final int connectionTimeout ,
37
37
final int soTimeout , final String user , final String password , final int database , final String clientName ) {
38
38
this (host , port , connectionTimeout , soTimeout , 0 , user , password , database , clientName );
39
39
}
40
40
41
- JedisFactory (final String host , final int port , final int connectionTimeout , final int soTimeout ,
41
+ protected JedisFactory (final String host , final int port , final int connectionTimeout , final int soTimeout ,
42
42
final int infiniteSoTimeout , final String user , final String password , final int database , final String clientName ) {
43
43
this (host , port , connectionTimeout , soTimeout , infiniteSoTimeout , user , password , database , clientName , false , null , null , null );
44
44
}
45
45
46
- JedisFactory (final String host , final int port , final int connectionTimeout ,
46
+ /**
47
+ * {@link #setHostAndPort(redis.clients.jedis.HostAndPort) setHostAndPort} must be called later.
48
+ */
49
+ protected JedisFactory (final int connectionTimeout , final int soTimeout , final int infiniteSoTimeout ,
50
+ final String user , final String password , final int database , final String clientName ) {
51
+ this (connectionTimeout , soTimeout , infiniteSoTimeout , user , password , database , clientName , false , null , null , null );
52
+ }
53
+
54
+ protected JedisFactory (final String host , final int port , final int connectionTimeout ,
47
55
final int soTimeout , final String password , final int database , final String clientName ,
48
56
final boolean ssl , final SSLSocketFactory sslSocketFactory , final SSLParameters sslParameters ,
49
57
final HostnameVerifier hostnameVerifier ) {
50
58
this (host , port , connectionTimeout , soTimeout , null , password , database , clientName , ssl , sslSocketFactory , sslParameters , hostnameVerifier );
51
59
}
52
60
53
- JedisFactory (final String host , final int port , final int connectionTimeout ,
61
+ protected JedisFactory (final String host , final int port , final int connectionTimeout ,
54
62
final int soTimeout , final String user , final String password , final int database , final String clientName ,
55
63
final boolean ssl , final SSLSocketFactory sslSocketFactory , final SSLParameters sslParameters ,
56
64
final HostnameVerifier hostnameVerifier ) {
57
65
this (host , port , connectionTimeout , soTimeout , 0 , user , password , database , clientName , ssl , sslSocketFactory , sslParameters , hostnameVerifier );
58
66
}
59
67
60
- JedisFactory (final HostAndPort hostAndPort , final JedisClientConfig clientConfig ) {
68
+ protected JedisFactory (final HostAndPort hostAndPort , final JedisClientConfig clientConfig ) {
61
69
this .hostAndPort .set (hostAndPort );
62
70
this .config = DefaultJedisClientConfig .copyConfig (clientConfig );
63
71
}
64
72
65
- JedisFactory (final String host , final int port , final int connectionTimeout , final int soTimeout ,
73
+ protected JedisFactory (final String host , final int port , final int connectionTimeout , final int soTimeout ,
66
74
final int infiniteSoTimeout , final String user , final String password , final int database ,
67
75
final String clientName , final boolean ssl , final SSLSocketFactory sslSocketFactory ,
68
76
final SSLParameters sslParameters , final HostnameVerifier hostnameVerifier ) {
77
+ this (connectionTimeout , soTimeout , infiniteSoTimeout , user , password , database , clientName , ssl , sslSocketFactory , sslParameters , hostnameVerifier );
69
78
this .hostAndPort .set (new HostAndPort (host , port ));
79
+ }
80
+
81
+ /**
82
+ * {@link #setHostAndPort(redis.clients.jedis.HostAndPort) setHostAndPort} must be called later.
83
+ */
84
+ protected JedisFactory (final int connectionTimeout , final int soTimeout , final int infiniteSoTimeout ,
85
+ final String user , final String password , final int database , final String clientName , final boolean ssl ,
86
+ final SSLSocketFactory sslSocketFactory , final SSLParameters sslParameters , final HostnameVerifier hostnameVerifier ) {
70
87
this .config = DefaultJedisClientConfig .builder ().withConnectionTimeoutMillis (connectionTimeout )
71
88
.withSoTimeoutMillis (soTimeout ).withInfiniteSoTimeoutMillis (infiniteSoTimeout ).withUser (user )
72
89
.withPassword (password ).withDatabse (database ).withClientName (clientName )
73
90
.withSsl (ssl ).withSslSocketFactory (sslSocketFactory )
74
91
.withSslParameters (sslParameters ).withHostnameVerifier (hostnameVerifier ).build ();
75
92
}
76
93
77
- JedisFactory (final URI uri , final int connectionTimeout , final int soTimeout ,
94
+ protected JedisFactory (final URI uri , final int connectionTimeout , final int soTimeout ,
78
95
final String clientName ) {
79
96
this (uri , connectionTimeout , soTimeout , clientName , null , null , null );
80
97
}
81
98
82
- JedisFactory (final URI uri , final int connectionTimeout , final int soTimeout ,
99
+ protected JedisFactory (final URI uri , final int connectionTimeout , final int soTimeout ,
83
100
final String clientName , final SSLSocketFactory sslSocketFactory ,
84
101
final SSLParameters sslParameters , final HostnameVerifier hostnameVerifier ) {
85
102
this (uri , connectionTimeout , soTimeout , 0 , clientName , sslSocketFactory , sslParameters , hostnameVerifier );
86
103
}
87
104
88
- JedisFactory (final URI uri , final int connectionTimeout , final int soTimeout ,
105
+ protected JedisFactory (final URI uri , final int connectionTimeout , final int soTimeout ,
89
106
final int infiniteSoTimeout , final String clientName , final SSLSocketFactory sslSocketFactory ,
90
107
final SSLParameters sslParameters , final HostnameVerifier hostnameVerifier ) {
91
108
if (!JedisURIHelper .isValid (uri )) {
@@ -105,6 +122,10 @@ public void setHostAndPort(final HostAndPort hostAndPort) {
105
122
this .hostAndPort .set (hostAndPort );
106
123
}
107
124
125
+ public void setPassword (final String password ) {
126
+ this .config .updatePassword (password );
127
+ }
128
+
108
129
@ Override
109
130
public void activateObject (PooledObject <Jedis > pooledJedis ) throws Exception {
110
131
final BinaryJedis jedis = pooledJedis .getObject ();
0 commit comments