1515 */
1616package org .springframework .data .redis .connection .jedis ;
1717
18- import redis .clients .jedis .BinaryJedis ;
19- import redis .clients .jedis .Client ;
18+ import redis .clients .jedis .Connection ;
19+ import redis .clients .jedis .ConnectionPool ;
2020import redis .clients .jedis .HostAndPort ;
2121import redis .clients .jedis .Jedis ;
2222import redis .clients .jedis .JedisCluster ;
23- import redis .clients .jedis .JedisClusterConnectionHandler ;
24- import redis .clients .jedis .JedisPool ;
23+ import redis .clients .jedis .providers .ClusterConnectionProvider ;
2524
2625import java .time .Duration ;
2726import java .util .ArrayList ;
3332import java .util .Map ;
3433import java .util .Map .Entry ;
3534import java .util .Set ;
36- import java .util .function .Function ;
3735
3836import org .apache .commons .logging .Log ;
3937import org .apache .commons .logging .LogFactory ;
@@ -119,9 +117,13 @@ public JedisClusterConnection(JedisCluster cluster) {
119117 new JedisClusterNodeResourceProvider (cluster , topologyProvider ), EXCEPTION_TRANSLATION );
120118 disposeClusterCommandExecutorOnClose = true ;
121119
120+
122121 try {
123- DirectFieldAccessor dfa = new DirectFieldAccessor (cluster );
124- clusterCommandExecutor .setMaxRedirects ((Integer ) dfa .getPropertyValue ("maxRedirections" ));
122+
123+ DirectFieldAccessor executorDfa = new DirectFieldAccessor (cluster );
124+ Object custerCommandExecutor = executorDfa .getPropertyValue ("executor" );
125+ DirectFieldAccessor dfa = new DirectFieldAccessor (custerCommandExecutor );
126+ clusterCommandExecutor .setMaxRedirects ((Integer ) dfa .getPropertyValue ("maxRedirects" ));
125127 } catch (Exception e ) {
126128 // ignore it and work with the executor default
127129 }
@@ -177,11 +179,6 @@ public Object execute(String command, byte[]... args) {
177179 @ Nullable
178180 @ Override
179181 public <T > T execute (String command , byte [] key , Collection <byte []> args ) {
180- return execute (command , key , args , it -> (T ) it .getOne ());
181- }
182-
183- @ Nullable
184- <T > T execute (String command , byte [] key , Collection <byte []> args , Function <Client , T > responseMapper ) {
185182
186183 Assert .notNull (command , "Command must not be null!" );
187184 Assert .notNull (key , "Key must not be null!" );
@@ -191,8 +188,9 @@ <T> T execute(String command, byte[] key, Collection<byte[]> args, Function<Clie
191188
192189 RedisClusterNode keyMaster = topologyProvider .getTopology ().getKeyServingMasterNode (key );
193190
194- return clusterCommandExecutor .executeCommandOnSingleNode ((JedisClusterCommandCallback <T >) client -> JedisClientUtils
195- .execute (command , EMPTY_2D_BYTE_ARRAY , commandArgs , () -> client , responseMapper ), keyMaster ).getValue ();
191+ return clusterCommandExecutor .executeCommandOnSingleNode ((JedisClusterCommandCallback <T >) client -> {
192+ return (T ) client .sendCommand (() -> JedisConverters .toBytes (command ), commandArgs );
193+ }, keyMaster ).getValue ();
196194 }
197195
198196 private static byte [][] getCommandArguments (byte [] key , Collection <byte []> args ) {
@@ -409,18 +407,13 @@ public void select(int dbIndex) {
409407
410408 @ Override
411409 public byte [] echo (byte [] message ) {
412-
413- try {
414- return cluster .echo (message );
415- } catch (Exception ex ) {
416- throw convertJedisAccessException (ex );
417- }
410+ throw new InvalidDataAccessApiUsageException ("Echo not supported in cluster mode." );
418411 }
419412
420413 @ Override
421414 public String ping () {
422415
423- return !clusterCommandExecutor .executeCommandOnAllNodes ((JedisClusterCommandCallback <String >) BinaryJedis ::ping )
416+ return !clusterCommandExecutor .executeCommandOnAllNodes ((JedisClusterCommandCallback <String >) Jedis ::ping )
424417 .resultsAsList ().isEmpty () ? "PONG" : null ;
425418
426419 }
@@ -429,7 +422,7 @@ public String ping() {
429422 public String ping (RedisClusterNode node ) {
430423
431424 return clusterCommandExecutor
432- .executeCommandOnSingleNode ((JedisClusterCommandCallback <String >) BinaryJedis ::ping , node ).getValue ();
425+ .executeCommandOnSingleNode ((JedisClusterCommandCallback <String >) Jedis ::ping , node ).getValue ();
433426 }
434427
435428 /*
@@ -552,8 +545,10 @@ public void clusterReplicate(RedisClusterNode master, RedisClusterNode replica)
552545 @ Override
553546 public Integer clusterGetSlotForKey (byte [] key ) {
554547
555- return clusterCommandExecutor .executeCommandOnArbitraryNode ((JedisClusterCommandCallback <Integer >) client -> client
556- .clusterKeySlot (JedisConverters .toString (key )).intValue ()).getValue ();
548+ return clusterCommandExecutor
549+ .executeCommandOnArbitraryNode (
550+ (JedisClusterCommandCallback <Integer >) client -> (int ) client .clusterKeySlot (JedisConverters .toString (key )))
551+ .getValue ();
557552 }
558553
559554 @ Override
@@ -709,7 +704,7 @@ static class JedisClusterNodeResourceProvider implements ClusterNodeResourceProv
709704
710705 private final JedisCluster cluster ;
711706 private final ClusterTopologyProvider topologyProvider ;
712- private final JedisClusterConnectionHandler connectionHandler ;
707+ private final ClusterConnectionProvider connectionHandler ;
713708
714709 /**
715710 * Creates new {@link JedisClusterNodeResourceProvider}.
@@ -726,7 +721,7 @@ static class JedisClusterNodeResourceProvider implements ClusterNodeResourceProv
726721
727722 PropertyAccessor accessor = new DirectFieldAccessFallbackBeanWrapper (cluster );
728723 this .connectionHandler = accessor .isReadableProperty ("connectionHandler" )
729- ? (JedisClusterConnectionHandler ) accessor .getPropertyValue ("connectionHandler" )
724+ ? (ClusterConnectionProvider ) accessor .getPropertyValue ("connectionHandler" )
730725 : null ;
731726 } else {
732727 this .connectionHandler = null ;
@@ -739,31 +734,31 @@ public Jedis getResourceForSpecificNode(RedisClusterNode node) {
739734
740735 Assert .notNull (node , "Cannot get Pool for 'null' node!" );
741736
742- JedisPool pool = getResourcePoolForSpecificNode (node );
737+ ConnectionPool pool = getResourcePoolForSpecificNode (node );
743738 if (pool != null ) {
744- return pool .getResource ();
739+ return new Jedis ( pool .getResource () );
745740 }
746741
747- Jedis connection = getConnectionForSpecificNode (node );
742+ Connection connection = getConnectionForSpecificNode (node );
748743
749744 if (connection != null ) {
750- return connection ;
745+ return new Jedis ( connection ) ;
751746 }
752747
753748 throw new DataAccessResourceFailureException (String .format ("Node %s is unknown to cluster" , node ));
754749 }
755750
756- private JedisPool getResourcePoolForSpecificNode (RedisClusterNode node ) {
751+ private ConnectionPool getResourcePoolForSpecificNode (RedisClusterNode node ) {
757752
758- Map <String , JedisPool > clusterNodes = cluster .getClusterNodes ();
753+ Map <String , ConnectionPool > clusterNodes = cluster .getClusterNodes ();
759754 if (clusterNodes .containsKey (node .asString ())) {
760755 return clusterNodes .get (node .asString ());
761756 }
762757
763758 return null ;
764759 }
765760
766- private Jedis getConnectionForSpecificNode (RedisClusterNode node ) {
761+ private Connection getConnectionForSpecificNode (RedisClusterNode node ) {
767762
768763 RedisClusterNode member = topologyProvider .getTopology ().lookup (node );
769764
@@ -773,7 +768,7 @@ private Jedis getConnectionForSpecificNode(RedisClusterNode node) {
773768 }
774769
775770 if (member != null && connectionHandler != null ) {
776- return connectionHandler .getConnectionFromNode (new HostAndPort (member .getHost (), member .getPort ()));
771+ return connectionHandler .getConnection (new HostAndPort (member .getHost (), member .getPort ()));
777772 }
778773
779774 return null ;
@@ -835,15 +830,15 @@ public ClusterTopology getTopology() {
835830
836831 Map <String , Exception > errors = new LinkedHashMap <>();
837832
838- List <Entry <String , JedisPool >> list = new ArrayList <>(cluster .getClusterNodes ().entrySet ());
833+ List <Entry <String , ConnectionPool >> list = new ArrayList <>(cluster .getClusterNodes ().entrySet ());
839834 Collections .shuffle (list );
840835
841- for (Entry <String , JedisPool > entry : list ) {
836+ for (Entry <String , ConnectionPool > entry : list ) {
842837
843- try (Jedis jedis = entry .getValue ().getResource ()) {
838+ try (Connection connection = entry .getValue ().getResource ()) {
844839
845840 time = System .currentTimeMillis ();
846- Set <RedisClusterNode > nodes = Converters .toSetOfRedisClusterNodes (jedis .clusterNodes ());
841+ Set <RedisClusterNode > nodes = Converters .toSetOfRedisClusterNodes (new Jedis ( connection ) .clusterNodes ());
847842
848843 synchronized (lock ) {
849844 cached = new ClusterTopology (nodes );
0 commit comments