Class ClusterCommandExecutor
java.lang.Object
org.springframework.data.redis.connection.ClusterCommandExecutor
- All Implemented Interfaces:
DisposableBean
ClusterCommandExecutor takes care of running commands across the known cluster nodes. By providing an
AsyncTaskExecutor the execution behavior can be configured.- Since:
- 1.7
- Author:
- Christoph Strobl, Mark Paluch, John Blum
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface for Redis 'low level' code using the cluster client directly.static interfaceCallback interface for Redis 'low level' code using the cluster client to execute multi key commands.static classClusterCommandExecutor.MultiNodeResultholds allClusterCommandExecutor.NodeResultof a command executed on multipleRedisClusterNode.static classClusterCommandExecutor.NodeResultencapsulates the actualvaluereturned by aClusterCommandExecutor.ClusterCommandCallbackon a givenRedisClusterNode. -
Constructor Summary
ConstructorsConstructorDescriptionClusterCommandExecutor(ClusterTopologyProvider topologyProvider, ClusterNodeResourceProvider resourceProvider, ExceptionTranslationStrategy exceptionTranslation) Create a newClusterCommandExecutor.ClusterCommandExecutor(ClusterTopologyProvider topologyProvider, ClusterNodeResourceProvider resourceProvider, ExceptionTranslationStrategy exceptionTranslation, AsyncTaskExecutor executor) -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()<S,T> ClusterCommandExecutor.MultiNodeResult<T> executeCommandAsyncOnNodes(ClusterCommandExecutor.ClusterCommandCallback<S, T> commandCallback, Iterable<RedisClusterNode> nodes) <S,T> ClusterCommandExecutor.MultiNodeResult<T> executeCommandOnAllNodes(ClusterCommandExecutor.ClusterCommandCallback<S, T> commandCallback) RunClusterCommandExecutor.ClusterCommandCallbackon all reachable master nodes.executeCommandOnArbitraryNode(ClusterCommandExecutor.ClusterCommandCallback<?, T> commandCallback) RunClusterCommandExecutor.ClusterCommandCallbackon a random node.<S,T> ClusterCommandExecutor.NodeResult<T> executeCommandOnSingleNode(ClusterCommandExecutor.ClusterCommandCallback<S, T> commandCallback, RedisClusterNode node) <S,T> ClusterCommandExecutor.MultiNodeResult<T> executeMultiKeyCommand(ClusterCommandExecutor.MultiKeyClusterCommandCallback<S, T> commandCallback, Iterable<byte[]> keys) RunClusterCommandExecutor.MultiKeyClusterCommandCallbackwith on a curated set of nodes serving one or more keys.voidsetMaxRedirects(int maxRedirects) Set the maximum number of redirects to follow onMOVEDorASK.
-
Constructor Details
-
ClusterCommandExecutor
public ClusterCommandExecutor(ClusterTopologyProvider topologyProvider, ClusterNodeResourceProvider resourceProvider, ExceptionTranslationStrategy exceptionTranslation) Create a newClusterCommandExecutor.- Parameters:
topologyProvider- must not be null.resourceProvider- must not be null.exceptionTranslation- must not be null.
-
ClusterCommandExecutor
public ClusterCommandExecutor(ClusterTopologyProvider topologyProvider, ClusterNodeResourceProvider resourceProvider, ExceptionTranslationStrategy exceptionTranslation, @Nullable AsyncTaskExecutor executor) - Parameters:
topologyProvider- must not be null.resourceProvider- must not be null.exceptionTranslation- must not be null.executor- the task executor to null, defaults toSimpleAsyncTaskExecutorif null.
-
-
Method Details
-
executeCommandOnArbitraryNode
public <T> ClusterCommandExecutor.NodeResult<T> executeCommandOnArbitraryNode(ClusterCommandExecutor.ClusterCommandCallback<?, T> commandCallback) RunClusterCommandExecutor.ClusterCommandCallbackon a random node.- Parameters:
commandCallback- must not be null.- Returns:
- never null.
-
executeCommandOnSingleNode
public <S,T> ClusterCommandExecutor.NodeResult<T> executeCommandOnSingleNode(ClusterCommandExecutor.ClusterCommandCallback<S, T> commandCallback, RedisClusterNode node) - Parameters:
commandCallback- must not be null.node- must not be null.- Returns:
- the
ClusterCommandExecutor.NodeResultfrom the single, targetedRedisClusterNode. - Throws:
IllegalArgumentException- in case no resource can be acquired for given node.
-
executeCommandOnAllNodes
public <S,T> ClusterCommandExecutor.MultiNodeResult<T> executeCommandOnAllNodes(ClusterCommandExecutor.ClusterCommandCallback<S, T> commandCallback) RunClusterCommandExecutor.ClusterCommandCallbackon all reachable master nodes.- Parameters:
commandCallback- must not be null.- Returns:
- never null.
- Throws:
ClusterCommandExecutionFailureException- if a failure occurs while executing the givencommandon any givennode.
-
executeCommandAsyncOnNodes
public <S,T> ClusterCommandExecutor.MultiNodeResult<T> executeCommandAsyncOnNodes(ClusterCommandExecutor.ClusterCommandCallback<S, T> commandCallback, Iterable<RedisClusterNode> nodes) - Parameters:
commandCallback- must not be null.nodes- must not be null.- Returns:
- never null.
- Throws:
ClusterCommandExecutionFailureException- if a failure occurs while executing the givencommandon any givennode.IllegalArgumentException- in case the node could not be resolved to a topology-known node
-
executeMultiKeyCommand
public <S,T> ClusterCommandExecutor.MultiNodeResult<T> executeMultiKeyCommand(ClusterCommandExecutor.MultiKeyClusterCommandCallback<S, T> commandCallback, Iterable<byte[]> keys) RunClusterCommandExecutor.MultiKeyClusterCommandCallbackwith on a curated set of nodes serving one or more keys.- Parameters:
commandCallback- must not be null.- Returns:
- never null.
- Throws:
ClusterCommandExecutionFailureException- if a failure occurs while executing the givencommand.
-
setMaxRedirects
public void setMaxRedirects(int maxRedirects) Set the maximum number of redirects to follow onMOVEDorASK.- Parameters:
maxRedirects- set to zero to suspend redirects.
-
destroy
- Specified by:
destroyin interfaceDisposableBean- Throws:
Exception
-