Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/redis/clients/jedis/JedisClusterCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package redis.clients.jedis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.exceptions.JedisAskDataException;
import redis.clients.jedis.exceptions.JedisClusterMaxAttemptsException;
import redis.clients.jedis.exceptions.JedisClusterOperationException;
Expand All @@ -11,6 +13,8 @@

public abstract class JedisClusterCommand<T> {

private static final Logger log = LoggerFactory.getLogger(JedisClusterCommand.class);

private final JedisClusterConnectionHandler connectionHandler;
private final int maxAttempts;

Expand Down Expand Up @@ -95,6 +99,7 @@ private T runWithRetries(final int slot, int attempts, boolean tryRandomNode, Je
}
} else {
if (tryRandomNode) {
log.debug("Trying to connect to random node");
connection = connectionHandler.getConnection();
} else {
connection = connectionHandler.getConnectionFromSlot(slot);
Expand All @@ -106,6 +111,7 @@ private T runWithRetries(final int slot, int attempts, boolean tryRandomNode, Je
} catch (JedisNoReachableClusterNodeException jnrcne) {
throw jnrcne;
} catch (JedisConnectionException jce) {
log.warn("Got retryable connection exception ({} attempts left)", attempts, jce);
// release current connection before recursion
releaseConnection(connection);
connection = null;
Expand All @@ -121,6 +127,7 @@ private T runWithRetries(final int slot, int attempts, boolean tryRandomNode, Je

return runWithRetries(slot, attempts - 1, tryRandomNode, redirect);
} catch (JedisRedirectionException jre) {
log.debug("Redirected by server to {}", jre.getTargetNode());
// if MOVED redirection occurred,
if (jre instanceof JedisMovedDataException) {
// it rebuilds cluster's slot cache recommended by Redis cluster specification
Expand Down