@@ -54,9 +54,9 @@ public final <T> T broadcastCommand(CommandObject<T> commandObject) {
5454    Map <String , ConnectionPool > connectionMap ;
5555
5656    if  (commandObject .getFlags ().contains (CommandObject .CommandFlag .READONLY )) {
57-          connectionMap  = provider .getConnectionMap ();
57+       connectionMap  = provider .getConnectionMap ();
5858    } else  {
59-          connectionMap  = provider .getPrimaryNodesConnectionMap ();
59+       connectionMap  = provider .getPrimaryNodesConnectionMap ();
6060    }
6161
6262    boolean  isErrored  = false ;
@@ -101,9 +101,9 @@ public final <T> T executeKeylessCommand(CommandObject<T> commandObject) {
101101
102102    RequiredConnectionType  connectionType ;
103103    if  (commandObject .getFlags ().contains (CommandObject .CommandFlag .READONLY )) {
104-          connectionType  = RequiredConnectionType .REPLICA ;
104+       connectionType  = RequiredConnectionType .REPLICA ;
105105    } else  {
106-          connectionType  = RequiredConnectionType .PRIMARY ;
106+       connectionType  = RequiredConnectionType .PRIMARY ;
107107    }
108108
109109    for  (int  attemptsLeft  = this .maxAttempts ; attemptsLeft  > 0 ; attemptsLeft --) {
@@ -122,15 +122,18 @@ public final <T> T executeKeylessCommand(CommandObject<T> commandObject) {
122122          continue ;
123123        }
124124
125-         boolean  reset  = handleConnectionProblem (attemptsLeft  - 1 , consecutiveConnectionFailures , deadline );
125+         boolean  reset  = handleConnectionProblem (attemptsLeft  - 1 , consecutiveConnectionFailures ,
126+           deadline );
126127        if  (reset ) {
127128          consecutiveConnectionFailures  = 0 ;
128129        }
129130      } catch  (JedisRedirectionException  jre ) {
130-         // For keyless commands, we don't follow redirections since we're not targeting a specific slot 
131+         // For keyless commands, we don't follow redirections since we're not targeting a specific 
132+         // slot 
131133        // Just retry with a different random node 
132134        lastException  = jre ;
133-         log .debug ("Received redirection for keyless command, retrying with different node: {}" , jre .getMessage ());
135+         log .debug ("Received redirection for keyless command, retrying with different node: {}" ,
136+           jre .getMessage ());
134137        consecutiveConnectionFailures  = 0 ;
135138      } finally  {
136139        IOUtils .closeQuietly (connection );
@@ -140,8 +143,8 @@ public final <T> T executeKeylessCommand(CommandObject<T> commandObject) {
140143      }
141144    }
142145
143-     JedisClusterOperationException  maxAttemptsException 
144-         =  new   JedisClusterOperationException ( "No more cluster attempts left." );
146+     JedisClusterOperationException  maxAttemptsException  =  new   JedisClusterOperationException ( 
147+         "No more cluster attempts left." );
145148    maxAttemptsException .addSuppressed (lastException );
146149    throw  maxAttemptsException ;
147150  }
@@ -213,47 +216,48 @@ private <T> T doExecuteCommand(CommandObject<T> commandObject, boolean toReplica
213216    throw  maxAttemptsException ;
214217  }
215218
216-     private  enum  RequiredConnectionType  {
217-         PRIMARY ,
218-         REPLICA 
219-     }
220-   
219+   private  enum  RequiredConnectionType  {
220+     PRIMARY , REPLICA 
221+   }
222+ 
221223  /** 
222-    * Gets a connection using round-robin distribution across all cluster nodes. 
223-    * This ensures even distribution of keyless commands across the cluster. 
224-    * 
224+    * Gets a connection using round-robin distribution across all cluster nodes. This ensures even 
225+    * distribution of keyless commands across the cluster. 
225226   * @return Connection from the next node in round-robin sequence 
226227   * @throws JedisClusterOperationException if no cluster nodes are available 
227228   */ 
228229  private  Connection  getNextConnection (RequiredConnectionType  connectionType ) {
229-        List <Map .Entry <String , ConnectionPool >> nodeList  = selectNextConnectionPool (connectionType );
230+     List <Map .Entry <String , ConnectionPool >> nodeList  = selectNextConnectionPool (connectionType );
230231    // Select node using round-robin distribution for true unified distribution 
231232    // Use modulo directly on the node list size to create a circular counter 
232-     int  roundRobinIndex  = roundRobinCounter .getAndUpdate (current  -> (current  + 1 ) % nodeList .size ());
233+     int  roundRobinIndex  = roundRobinCounter 
234+         .getAndUpdate (current  -> (current  + 1 ) % nodeList .size ());
233235    Map .Entry <String , ConnectionPool > selectedEntry  = nodeList .get (roundRobinIndex );
234236    ConnectionPool  pool  = selectedEntry .getValue ();
235237
236238    return  pool .getResource ();
237239  }
238240
239-     private  List <Map .Entry <String , ConnectionPool >> selectNextConnectionPool (RequiredConnectionType  connectionType ) {
240-         Map <String , ConnectionPool > connectionMap ;
241- 
242-         // NOTE(imalinovskyi): If we need to connect to replica, we use all nodes, otherwise we use only primary nodes 
243-         if  (connectionType  == RequiredConnectionType .REPLICA ) {
244-             connectionMap  = provider .getConnectionMap ();
245-         } else  {
246-             connectionMap  = provider .getPrimaryNodesConnectionMap ();
247-         }
241+   private  List <Map .Entry <String , ConnectionPool >> selectNextConnectionPool (
242+       RequiredConnectionType  connectionType ) {
243+     Map <String , ConnectionPool > connectionMap ;
248244
249-         if  (connectionMap .isEmpty ()) {
250-           throw  new  JedisClusterOperationException ("No cluster nodes available." );
251-         }
245+     // NOTE(imalinovskyi): If we need to connect to replica, we use all nodes, otherwise we use only 
246+     // primary nodes 
247+     if  (connectionType  == RequiredConnectionType .REPLICA ) {
248+       connectionMap  = provider .getConnectionMap ();
249+     } else  {
250+       connectionMap  = provider .getPrimaryNodesConnectionMap ();
251+     }
252252
253-          // Convert connection map to list for round-robin access 
254-          return   new  ArrayList <>( connectionMap . entrySet () );
253+     if  ( connectionMap . isEmpty ()) { 
254+       throw   new  JedisClusterOperationException ( "No cluster nodes available." );
255255    }
256256
257+     // Convert connection map to list for round-robin access 
258+     return  new  ArrayList <>(connectionMap .entrySet ());
259+   }
260+ 
257261    /** 
258262   * WARNING: This method is accessible for the purpose of testing. 
259263   * This should not be used or overriden. 
@@ -265,7 +269,6 @@ protected <T> T execute(Connection connection, CommandObject<T> commandObject) {
265269
266270  /** 
267271   * Related values should be reset if <code>TRUE</code> is returned. 
268-    * 
269272   * @param attemptsLeft 
270273   * @param consecutiveConnectionFailures 
271274   * @param doneDeadline 
0 commit comments