public class ClusterCommandExecutor extends java.lang.Object implements CommandExecutor
| Modifier and Type | Field and Description |
|---|---|
protected CommandFlagsRegistry |
flags |
protected int |
maxAttempts |
protected java.time.Duration |
maxTotalRetriesDuration |
ClusterConnectionProvider |
provider |
| Constructor and Description |
|---|
ClusterCommandExecutor(ClusterConnectionProvider provider,
int maxAttempts,
java.time.Duration maxTotalRetriesDuration)
Deprecated.
use
ClusterCommandExecutor(ClusterConnectionProvider, int, Duration, CommandFlagsRegistry)
instead. This constructor will be removed in the next major version. |
ClusterCommandExecutor(ClusterConnectionProvider provider,
int maxAttempts,
java.time.Duration maxTotalRetriesDuration,
CommandFlagsRegistry flags) |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
broadcastCommand(CommandObject<T> commandObject,
boolean primaryOnly)
Broadcast a command to cluster nodes.
|
void |
close() |
protected <T> T |
execute(Connection connection,
CommandObject<T> commandObject)
WARNING: This method is accessible for the purpose of testing.
|
<T> T |
executeCommand(CommandObject<T> commandObject) |
<T> T |
executeCommandToReplica(CommandObject<T> commandObject) |
<T> T |
executeMultiShardCommand(java.util.List<CommandObject<T>> commandObjects)
Execute multiple command objects across different cluster shards and aggregate the results.
|
protected void |
sleep(long sleepMillis)
WARNING: This method is accessible for the purpose of testing.
|
public final ClusterConnectionProvider provider
protected final int maxAttempts
protected final java.time.Duration maxTotalRetriesDuration
protected final CommandFlagsRegistry flags
@Deprecated public ClusterCommandExecutor(ClusterConnectionProvider provider, int maxAttempts, java.time.Duration maxTotalRetriesDuration)
ClusterCommandExecutor(ClusterConnectionProvider, int, Duration, CommandFlagsRegistry)
instead. This constructor will be removed in the next major version.public ClusterCommandExecutor(ClusterConnectionProvider provider, int maxAttempts, java.time.Duration maxTotalRetriesDuration, CommandFlagsRegistry flags)
public void close()
close in interface java.lang.AutoCloseablepublic final <T> T broadcastCommand(CommandObject<T> commandObject, boolean primaryOnly)
This method uses doExecuteCommand(redis.clients.jedis.CommandObject<T>, redis.clients.jedis.executors.ConnectionResolver, boolean) with a SingleConnectionResolver for each
node, which adds retry logic and connection failure handling to broadcast commands.
Redirections are not followed since we want to execute on specific nodes.
Error handling depends on the command's response policy:
ONE_SUCCEEDED: Returns success if at least one node succeedsJedisBroadcastException if any node failscommandObject - the command to broadcastprimaryOnly - if true, broadcast only to primary nodes; if false, broadcast to all nodes
including replicasJedisBroadcastException - if error handling criteria based on response policy are not metpublic final <T> T executeMultiShardCommand(java.util.List<CommandObject<T>> commandObjects)
This method is designed for commands that need to operate on keys distributed across multiple hash slots (e.g., DEL, EXISTS, MGET with keys from different slots). Each CommandObject in the list is executed on its appropriate shard based on the key's hash slot, and the results are aggregated using the command's response policy.
Error handling depends on the command's response policy:
ONE_SUCCEEDED: Returns success if at least one shard succeedsJedisBroadcastException if any shard failsT - the return type of the commandcommandObjects - list of CommandObject instances, each targeting keys in the same hash slotJedisBroadcastException - if error handling criteria based on response policy are not metpublic final <T> T executeCommand(CommandObject<T> commandObject)
executeCommand in interface CommandExecutorpublic final <T> T executeCommandToReplica(CommandObject<T> commandObject)
@VisibleForTesting protected <T> T execute(Connection connection, CommandObject<T> commandObject)
@VisibleForTesting protected void sleep(long sleepMillis)
Copyright © 2026. All rights reserved.