@@ -60,8 +60,7 @@ public UnifiedJedis() {
60
60
}
61
61
62
62
public UnifiedJedis (HostAndPort hostAndPort ) {
63
- // this(new Connection(hostAndPort));
64
- this (new PooledConnectionProvider (hostAndPort ));
63
+ this (new PooledConnectionProvider (hostAndPort ), (RedisProtocol ) null );
65
64
}
66
65
67
66
public UnifiedJedis (final String url ) {
@@ -89,27 +88,15 @@ public UnifiedJedis(final URI uri, JedisClientConfig config) {
89
88
}
90
89
91
90
public UnifiedJedis (HostAndPort hostAndPort , JedisClientConfig clientConfig ) {
92
- // this(new Connection(hostAndPort, clientConfig));
93
- this (new PooledConnectionProvider (hostAndPort , clientConfig ));
94
- RedisProtocol proto = clientConfig .getRedisProtocol ();
95
- if (proto != null ) commandObjects .setProtocol (proto );
91
+ this (new PooledConnectionProvider (hostAndPort , clientConfig ), clientConfig .getRedisProtocol ());
96
92
}
97
93
98
94
public UnifiedJedis (ConnectionProvider provider ) {
99
- this .provider = provider ;
100
- this .executor = new DefaultCommandExecutor (provider );
101
- this .commandObjects = new CommandObjects ();
102
- this .graphCommandObjects = new GraphCommandObjects (this );
103
- this .graphCommandObjects .setBaseCommandArgumentsCreator ((comm ) -> this .commandObjects .commandArguments (comm ));
104
- try (Connection conn = this .provider .getConnection ()) {
105
- if (conn != null ) {
106
- RedisProtocol proto = conn .getRedisProtocol ();
107
- if (proto != null ) commandObjects .setProtocol (proto );
108
- }
109
- //} catch (JedisAccessControlException ace) {
110
- } catch (JedisException je ) { // TODO: use specific exception(s)
111
- // use default protocol
112
- }
95
+ this (new DefaultCommandExecutor (provider ), provider );
96
+ }
97
+
98
+ protected UnifiedJedis (ConnectionProvider provider , RedisProtocol protocol ) {
99
+ this (new DefaultCommandExecutor (provider ), provider , new CommandObjects (), protocol );
113
100
}
114
101
115
102
/**
@@ -142,69 +129,60 @@ public UnifiedJedis(Connection connection) {
142
129
this .provider = null ;
143
130
this .executor = new SimpleCommandExecutor (connection );
144
131
this .commandObjects = new CommandObjects ();
145
- this .graphCommandObjects = new GraphCommandObjects (this );
146
132
RedisProtocol proto = connection .getRedisProtocol ();
147
- if (proto == RedisProtocol .RESP3 ) this .commandObjects .setProtocol (proto );
133
+ if (proto != null ) this .commandObjects .setProtocol (proto );
134
+ this .graphCommandObjects = new GraphCommandObjects (this );
148
135
}
149
136
137
+ @ Deprecated
150
138
public UnifiedJedis (Set <HostAndPort > jedisClusterNodes , JedisClientConfig clientConfig , int maxAttempts ) {
151
- this (new ClusterConnectionProvider (jedisClusterNodes , clientConfig ), maxAttempts ,
152
- Duration .ofMillis (maxAttempts * clientConfig .getSocketTimeoutMillis ()));
153
- RedisProtocol proto = clientConfig .getRedisProtocol ();
154
- if (proto != null ) commandObjects .setProtocol (proto );
139
+ this (jedisClusterNodes , clientConfig , maxAttempts , Duration .ofMillis (maxAttempts * clientConfig .getSocketTimeoutMillis ()));
155
140
}
156
141
157
- public UnifiedJedis (Set <HostAndPort > jedisClusterNodes , JedisClientConfig clientConfig , int maxAttempts , Duration maxTotalRetriesDuration ) {
158
- this (new ClusterConnectionProvider (jedisClusterNodes , clientConfig ), maxAttempts , maxTotalRetriesDuration );
159
- RedisProtocol proto = clientConfig .getRedisProtocol ();
160
- if (proto != null ) commandObjects .setProtocol (proto );
142
+ @ Deprecated
143
+ public UnifiedJedis (Set <HostAndPort > jedisClusterNodes , JedisClientConfig clientConfig , int maxAttempts ,
144
+ Duration maxTotalRetriesDuration ) {
145
+ this (new ClusterConnectionProvider (jedisClusterNodes , clientConfig ), maxAttempts , maxTotalRetriesDuration ,
146
+ clientConfig .getRedisProtocol ());
161
147
}
162
148
149
+ @ Deprecated
163
150
public UnifiedJedis (Set <HostAndPort > jedisClusterNodes , JedisClientConfig clientConfig ,
164
151
GenericObjectPoolConfig <Connection > poolConfig , int maxAttempts , Duration maxTotalRetriesDuration ) {
165
- this (new ClusterConnectionProvider (jedisClusterNodes , clientConfig , poolConfig ), maxAttempts , maxTotalRetriesDuration );
166
- RedisProtocol proto = clientConfig .getRedisProtocol ();
167
- if (proto != null ) commandObjects .setProtocol (proto );
152
+ this (new ClusterConnectionProvider (jedisClusterNodes , clientConfig , poolConfig ), maxAttempts ,
153
+ maxTotalRetriesDuration , clientConfig .getRedisProtocol ());
168
154
}
169
155
156
+ // Uses a fetched connection to process protocol. Should be avoided if possible.
170
157
public UnifiedJedis (ClusterConnectionProvider provider , int maxAttempts , Duration maxTotalRetriesDuration ) {
171
- this .provider = provider ;
172
- this .executor = new ClusterCommandExecutor (provider , maxAttempts , maxTotalRetriesDuration );
173
- this .commandObjects = new ClusterCommandObjects ();
174
- this .graphCommandObjects = new GraphCommandObjects (this );
175
- this .graphCommandObjects .setBaseCommandArgumentsCreator ((comm ) -> this .commandObjects .commandArguments (comm ));
158
+ this (new ClusterCommandExecutor (provider , maxAttempts , maxTotalRetriesDuration ), provider ,
159
+ new ClusterCommandObjects ());
160
+ }
161
+
162
+ protected UnifiedJedis (ClusterConnectionProvider provider , int maxAttempts , Duration maxTotalRetriesDuration ,
163
+ RedisProtocol protocol ) {
164
+ this (new ClusterCommandExecutor (provider , maxAttempts , maxTotalRetriesDuration ), provider ,
165
+ new ClusterCommandObjects (), protocol );
176
166
}
177
167
178
168
/**
179
169
* @deprecated Sharding/Sharded feature will be removed in next major release.
180
170
*/
181
171
@ Deprecated
182
172
public UnifiedJedis (ShardedConnectionProvider provider ) {
183
- this .provider = provider ;
184
- this .executor = new DefaultCommandExecutor (provider );
185
- this .commandObjects = new ShardedCommandObjects (provider .getHashingAlgo ());
186
- this .graphCommandObjects = new GraphCommandObjects (this );
187
- this .graphCommandObjects .setBaseCommandArgumentsCreator ((comm ) -> this .commandObjects .commandArguments (comm ));
173
+ this (new DefaultCommandExecutor (provider ), provider , new ShardedCommandObjects (provider .getHashingAlgo ()));
188
174
}
189
175
190
176
/**
191
177
* @deprecated Sharding/Sharded feature will be removed in next major release.
192
178
*/
193
179
@ Deprecated
194
180
public UnifiedJedis (ShardedConnectionProvider provider , Pattern tagPattern ) {
195
- this .provider = provider ;
196
- this .executor = new DefaultCommandExecutor (provider );
197
- this .commandObjects = new ShardedCommandObjects (provider .getHashingAlgo (), tagPattern );
198
- this .graphCommandObjects = new GraphCommandObjects (this );
199
- this .graphCommandObjects .setBaseCommandArgumentsCreator ((comm ) -> this .commandObjects .commandArguments (comm ));
181
+ this (new DefaultCommandExecutor (provider ), provider , new ShardedCommandObjects (provider .getHashingAlgo (), tagPattern ));
200
182
}
201
183
202
184
public UnifiedJedis (ConnectionProvider provider , int maxAttempts , Duration maxTotalRetriesDuration ) {
203
- this .provider = provider ;
204
- this .executor = new RetryableCommandExecutor (provider , maxAttempts , maxTotalRetriesDuration );
205
- this .commandObjects = new CommandObjects ();
206
- this .graphCommandObjects = new GraphCommandObjects (this );
207
- this .graphCommandObjects .setBaseCommandArgumentsCreator ((comm ) -> this .commandObjects .commandArguments (comm ));
185
+ this (new RetryableCommandExecutor (provider , maxAttempts , maxTotalRetriesDuration ), provider );
208
186
}
209
187
210
188
/**
@@ -215,11 +193,7 @@ public UnifiedJedis(ConnectionProvider provider, int maxAttempts, Duration maxTo
215
193
* <p>
216
194
*/
217
195
public UnifiedJedis (MultiClusterPooledConnectionProvider provider ) {
218
- this .provider = provider ;
219
- this .executor = new CircuitBreakerCommandExecutor (provider );
220
- this .commandObjects = new CommandObjects ();
221
- this .graphCommandObjects = new GraphCommandObjects (this );
222
- this .graphCommandObjects .setBaseCommandArgumentsCreator ((comm ) -> this .commandObjects .commandArguments (comm ));
196
+ this (new CircuitBreakerCommandExecutor (provider ), provider );
223
197
}
224
198
225
199
/**
@@ -229,9 +203,36 @@ public UnifiedJedis(MultiClusterPooledConnectionProvider provider) {
229
203
* {@link UnifiedJedis#provider} is accessed.
230
204
*/
231
205
public UnifiedJedis (CommandExecutor executor ) {
232
- this .provider = null ;
206
+ this (executor , (ConnectionProvider ) null );
207
+ }
208
+
209
+ private UnifiedJedis (CommandExecutor executor , ConnectionProvider provider ) {
210
+ this (executor , provider , new CommandObjects ());
211
+ }
212
+
213
+ // Uses a fetched connection to process protocol. Should be avoided if possible.
214
+ private UnifiedJedis (CommandExecutor executor , ConnectionProvider provider , CommandObjects commandObjects ) {
215
+ this (executor , provider , commandObjects , null );
216
+ if (this .provider != null ) {
217
+ try (Connection conn = this .provider .getConnection ()) {
218
+ if (conn != null ) {
219
+ RedisProtocol proto = conn .getRedisProtocol ();
220
+ if (proto != null ) this .commandObjects .setProtocol (proto );
221
+ }
222
+ } catch (JedisException je ) { }
223
+ }
224
+ }
225
+
226
+ private UnifiedJedis (CommandExecutor executor , ConnectionProvider provider , CommandObjects commandObjects ,
227
+ RedisProtocol protocol ) {
228
+ this .provider = provider ;
233
229
this .executor = executor ;
234
- this .commandObjects = new CommandObjects ();
230
+
231
+ this .commandObjects = commandObjects ;
232
+ if (protocol != null ) {
233
+ this .commandObjects .setProtocol (protocol );
234
+ }
235
+
235
236
this .graphCommandObjects = new GraphCommandObjects (this );
236
237
this .graphCommandObjects .setBaseCommandArgumentsCreator ((comm ) -> this .commandObjects .commandArguments (comm ));
237
238
}
@@ -241,6 +242,7 @@ public void close() {
241
242
IOUtils .closeQuietly (this .executor );
242
243
}
243
244
245
+ @ Deprecated
244
246
protected final void setProtocol (RedisProtocol protocol ) {
245
247
this .protocol = protocol ;
246
248
this .commandObjects .setProtocol (this .protocol );
0 commit comments