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 influenced.- Since:
- 1.7
- Author:
- Christoph Strobl, Mark Paluch
-
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 actual value returned by aClusterCommandExecutor.ClusterCommandCallbackon a givenRedisClusterNode. -
Constructor Summary
ConstructorsConstructorDescriptionClusterCommandExecutor(ClusterTopologyProvider topologyProvider, ClusterNodeResourceProvider resourceProvider, ExceptionTranslationStrategy exceptionTranslation) Create a new instance ofClusterCommandExecutor.ClusterCommandExecutor(ClusterTopologyProvider topologyProvider, ClusterNodeResourceProvider resourceProvider, ExceptionTranslationStrategy exceptionTranslation, AsyncTaskExecutor executor) -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()<S,T> ClusterCommandExecutor.MultiNodeResult<T> executeCommandAsyncOnNodes(ClusterCommandExecutor.ClusterCommandCallback<S, T> callback, Iterable<RedisClusterNode> nodes) <S,T> ClusterCommandExecutor.MultiNodeResult<T> RunClusterCommandExecutor.ClusterCommandCallbackon all reachable master nodes.RunClusterCommandExecutor.ClusterCommandCallbackon a random node.<S,T> ClusterCommandExecutor.NodeResult<T> executeCommandOnSingleNode(ClusterCommandExecutor.ClusterCommandCallback<S, T> cmd, RedisClusterNode node) <S,T> ClusterCommandExecutor.MultiNodeResult<T> executeMultiKeyCommand(ClusterCommandExecutor.MultiKeyClusterCommandCallback<S, T> cmd, 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 new instance ofClusterCommandExecutor.- 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- can be null. Defaulted toThreadPoolTaskExecutor.
-
-
Method Details
-
executeCommandOnArbitraryNode
public <T> ClusterCommandExecutor.NodeResult<T> executeCommandOnArbitraryNode(ClusterCommandExecutor.ClusterCommandCallback<?, T> cmd) RunClusterCommandExecutor.ClusterCommandCallbackon a random node.- Parameters:
cmd- must not be null.- Returns:
- never null.
-
executeCommandOnSingleNode
public <S,T> ClusterCommandExecutor.NodeResult<T> executeCommandOnSingleNode(ClusterCommandExecutor.ClusterCommandCallback<S, T> cmd, RedisClusterNode node) - Parameters:
cmd- must not be null.node- must not be null.- Returns:
- Throws:
IllegalArgumentException- in case no resource can be acquired for given node.
-
executeCommandOnAllNodes
public <S,T> ClusterCommandExecutor.MultiNodeResult<T> executeCommandOnAllNodes(ClusterCommandExecutor.ClusterCommandCallback<S, T> cmd) RunClusterCommandExecutor.ClusterCommandCallbackon all reachable master nodes.- Parameters:
cmd- must not be null.- Returns:
- never null.
- Throws:
ClusterCommandExecutionFailureException
-
executeCommandAsyncOnNodes
public <S,T> ClusterCommandExecutor.MultiNodeResult<T> executeCommandAsyncOnNodes(ClusterCommandExecutor.ClusterCommandCallback<S, T> callback, Iterable<RedisClusterNode> nodes) - Parameters:
callback- must not be null.nodes- must not be null.- Returns:
- never null.
- Throws:
ClusterCommandExecutionFailureExceptionIllegalArgumentException- 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> cmd, Iterable<byte[]> keys) RunClusterCommandExecutor.MultiKeyClusterCommandCallbackwith on a curated set of nodes serving one or more keys.- Parameters:
cmd- must not be null.- Returns:
- never null.
- Throws:
ClusterCommandExecutionFailureException
-
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
-