@@ -60,8 +60,7 @@ public UnifiedJedis() {
6060 }
6161
6262 public UnifiedJedis (HostAndPort hostAndPort ) {
63- // this(new Connection(hostAndPort));
64- this (new PooledConnectionProvider (hostAndPort ));
63+ this (new PooledConnectionProvider (hostAndPort ), (RedisProtocol ) null );
6564 }
6665
6766 public UnifiedJedis (final String url ) {
@@ -89,27 +88,15 @@ public UnifiedJedis(final URI uri, JedisClientConfig config) {
8988 }
9089
9190 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 ());
9692 }
9793
9894 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 );
113100 }
114101
115102 /**
@@ -142,69 +129,60 @@ public UnifiedJedis(Connection connection) {
142129 this .provider = null ;
143130 this .executor = new SimpleCommandExecutor (connection );
144131 this .commandObjects = new CommandObjects ();
145- this .graphCommandObjects = new GraphCommandObjects (this );
146132 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 );
148135 }
149136
137+ @ Deprecated
150138 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 ()));
155140 }
156141
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 ());
161147 }
162148
149+ @ Deprecated
163150 public UnifiedJedis (Set <HostAndPort > jedisClusterNodes , JedisClientConfig clientConfig ,
164151 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 ());
168154 }
169155
156+ // Uses a fetched connection to process protocol. Should be avoided if possible.
170157 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 );
176166 }
177167
178168 /**
179169 * @deprecated Sharding/Sharded feature will be removed in next major release.
180170 */
181171 @ Deprecated
182172 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 ()));
188174 }
189175
190176 /**
191177 * @deprecated Sharding/Sharded feature will be removed in next major release.
192178 */
193179 @ Deprecated
194180 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 ));
200182 }
201183
202184 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 );
208186 }
209187
210188 /**
@@ -215,11 +193,7 @@ public UnifiedJedis(ConnectionProvider provider, int maxAttempts, Duration maxTo
215193 * <p>
216194 */
217195 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 );
223197 }
224198
225199 /**
@@ -229,9 +203,36 @@ public UnifiedJedis(MultiClusterPooledConnectionProvider provider) {
229203 * {@link UnifiedJedis#provider} is accessed.
230204 */
231205 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 ;
233229 this .executor = executor ;
234- this .commandObjects = new CommandObjects ();
230+
231+ this .commandObjects = commandObjects ;
232+ if (protocol != null ) {
233+ this .commandObjects .setProtocol (protocol );
234+ }
235+
235236 this .graphCommandObjects = new GraphCommandObjects (this );
236237 this .graphCommandObjects .setBaseCommandArgumentsCreator ((comm ) -> this .commandObjects .commandArguments (comm ));
237238 }
@@ -241,6 +242,7 @@ public void close() {
241242 IOUtils .closeQuietly (this .executor );
242243 }
243244
245+ @ Deprecated
244246 protected final void setProtocol (RedisProtocol protocol ) {
245247 this .protocol = protocol ;
246248 this .commandObjects .setProtocol (this .protocol );
0 commit comments