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
Modifier and TypeClassDescriptionstatic interface
Callback interface for Redis 'low level' code using the cluster client directly.static interface
Callback interface for Redis 'low level' code using the cluster client to execute multi key commands.static class
ClusterCommandExecutor.MultiNodeResult
holds allClusterCommandExecutor.NodeResult
of a command executed on multipleRedisClusterNode
.static class
ClusterCommandExecutor.NodeResult
encapsulates the actual value returned by aClusterCommandExecutor.ClusterCommandCallback
on a givenRedisClusterNode
. -
Constructor Summary
ConstructorDescriptionClusterCommandExecutor
(ClusterTopologyProvider topologyProvider, ClusterNodeResourceProvider resourceProvider, ExceptionTranslationStrategy exceptionTranslation) Create a new instance ofClusterCommandExecutor
.ClusterCommandExecutor
(ClusterTopologyProvider topologyProvider, ClusterNodeResourceProvider resourceProvider, ExceptionTranslationStrategy exceptionTranslation, AsyncTaskExecutor executor) -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
<S,
T> ClusterCommandExecutor.MultiNodeResult<T> executeCommandAsyncOnNodes
(ClusterCommandExecutor.ClusterCommandCallback<S, T> callback, Iterable<RedisClusterNode> nodes) <S,
T> ClusterCommandExecutor.MultiNodeResult<T> RunClusterCommandExecutor.ClusterCommandCallback
on all reachable master nodes.RunClusterCommandExecutor.ClusterCommandCallback
on 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.MultiKeyClusterCommandCallback
with on a curated set of nodes serving one or more keys.void
setMaxRedirects
(int maxRedirects) Set the maximum number of redirects to follow onMOVED
orASK
.
-
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.ClusterCommandCallback
on 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.ClusterCommandCallback
on 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:
ClusterCommandExecutionFailureException
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> cmd, Iterable<byte[]> keys) RunClusterCommandExecutor.MultiKeyClusterCommandCallback
with 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 onMOVED
orASK
.- Parameters:
maxRedirects
- set to zero to suspend redirects.
-
destroy
- Specified by:
destroy
in interfaceDisposableBean
- Throws:
Exception
-