@@ -104,9 +104,9 @@ public final <T> T executeKeylessCommand(CommandObject<T> commandObject) {
104104
105105 RequiredConnectionType connectionType ;
106106 if (commandObject .getFlags ().contains (CommandObject .CommandFlag .READONLY )) {
107- connectionType = RequiredConnectionType .REPLICA ;
107+ connectionType = RequiredConnectionType .REPLICA ;
108108 } else {
109- connectionType = RequiredConnectionType .PRIMARY ;
109+ connectionType = RequiredConnectionType .PRIMARY ;
110110 }
111111
112112 for (int attemptsLeft = this .maxAttempts ; attemptsLeft > 0 ; attemptsLeft --) {
@@ -125,15 +125,18 @@ public final <T> T executeKeylessCommand(CommandObject<T> commandObject) {
125125 continue ;
126126 }
127127
128- boolean reset = handleConnectionProblem (attemptsLeft - 1 , consecutiveConnectionFailures , deadline );
128+ boolean reset = handleConnectionProblem (attemptsLeft - 1 , consecutiveConnectionFailures ,
129+ deadline );
129130 if (reset ) {
130131 consecutiveConnectionFailures = 0 ;
131132 }
132133 } catch (JedisRedirectionException jre ) {
133- // For keyless commands, we don't follow redirections since we're not targeting a specific slot
134+ // For keyless commands, we don't follow redirections since we're not targeting a specific
135+ // slot
134136 // Just retry with a different random node
135137 lastException = jre ;
136- log .debug ("Received redirection for keyless command, retrying with different node: {}" , jre .getMessage ());
138+ log .debug ("Received redirection for keyless command, retrying with different node: {}" ,
139+ jre .getMessage ());
137140 consecutiveConnectionFailures = 0 ;
138141 } finally {
139142 IOUtils .closeQuietly (connection );
@@ -143,8 +146,8 @@ public final <T> T executeKeylessCommand(CommandObject<T> commandObject) {
143146 }
144147 }
145148
146- JedisClusterOperationException maxAttemptsException
147- = new JedisClusterOperationException ( "No more cluster attempts left." );
149+ JedisClusterOperationException maxAttemptsException = new JedisClusterOperationException (
150+ "No more cluster attempts left." );
148151 maxAttemptsException .addSuppressed (lastException );
149152 throw maxAttemptsException ;
150153 }
@@ -216,47 +219,48 @@ private <T> T doExecuteCommand(CommandObject<T> commandObject, boolean toReplica
216219 throw maxAttemptsException ;
217220 }
218221
219- private enum RequiredConnectionType {
220- PRIMARY ,
221- REPLICA
222- }
223-
222+ private enum RequiredConnectionType {
223+ PRIMARY , REPLICA
224+ }
225+
224226 /**
225- * Gets a connection using round-robin distribution across all cluster nodes.
226- * This ensures even distribution of keyless commands across the cluster.
227- *
227+ * Gets a connection using round-robin distribution across all cluster nodes. This ensures even
228+ * distribution of keyless commands across the cluster.
228229 * @return Connection from the next node in round-robin sequence
229230 * @throws JedisClusterOperationException if no cluster nodes are available
230231 */
231232 private Connection getNextConnection (RequiredConnectionType connectionType ) {
232- List <Map .Entry <String , ConnectionPool >> nodeList = selectNextConnectionPool (connectionType );
233+ List <Map .Entry <String , ConnectionPool >> nodeList = selectNextConnectionPool (connectionType );
233234 // Select node using round-robin distribution for true unified distribution
234235 // Use modulo directly on the node list size to create a circular counter
235- int roundRobinIndex = roundRobinCounter .getAndUpdate (current -> (current + 1 ) % nodeList .size ());
236+ int roundRobinIndex = roundRobinCounter
237+ .getAndUpdate (current -> (current + 1 ) % nodeList .size ());
236238 Map .Entry <String , ConnectionPool > selectedEntry = nodeList .get (roundRobinIndex );
237239 ConnectionPool pool = selectedEntry .getValue ();
238240
239241 return pool .getResource ();
240242 }
241243
242- private List <Map .Entry <String , ConnectionPool >> selectNextConnectionPool (RequiredConnectionType connectionType ) {
243- Map <String , ConnectionPool > connectionMap ;
244-
245- // NOTE(imalinovskyi): If we need to connect to replica, we use all nodes, otherwise we use only primary nodes
246- if (connectionType == RequiredConnectionType .REPLICA ) {
247- connectionMap = provider .getConnectionMap ();
248- } else {
249- connectionMap = provider .getPrimaryNodesConnectionMap ();
250- }
244+ private List <Map .Entry <String , ConnectionPool >> selectNextConnectionPool (
245+ RequiredConnectionType connectionType ) {
246+ Map <String , ConnectionPool > connectionMap ;
251247
252- if (connectionMap .isEmpty ()) {
253- throw new JedisClusterOperationException ("No cluster nodes available." );
254- }
248+ // NOTE(imalinovskyi): If we need to connect to replica, we use all nodes, otherwise we use only
249+ // primary nodes
250+ if (connectionType == RequiredConnectionType .REPLICA ) {
251+ connectionMap = provider .getConnectionMap ();
252+ } else {
253+ connectionMap = provider .getPrimaryNodesConnectionMap ();
254+ }
255255
256- // Convert connection map to list for round-robin access
257- return new ArrayList <>( connectionMap . entrySet () );
256+ if ( connectionMap . isEmpty ()) {
257+ throw new JedisClusterOperationException ( "No cluster nodes available." );
258258 }
259259
260+ // Convert connection map to list for round-robin access
261+ return new ArrayList <>(connectionMap .entrySet ());
262+ }
263+
260264 /**
261265 * WARNING: This method is accessible for the purpose of testing.
262266 * This should not be used or overriden.
@@ -268,7 +272,6 @@ protected <T> T execute(Connection connection, CommandObject<T> commandObject) {
268272
269273 /**
270274 * Related values should be reset if <code>TRUE</code> is returned.
271- *
272275 * @param attemptsLeft
273276 * @param consecutiveConnectionFailures
274277 * @param doneDeadline
0 commit comments