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
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 actualvalue
returned by aClusterCommandExecutor.ClusterCommandCallback
on a givenRedisClusterNode
. -
Constructor Summary
ConstructorDescriptionClusterCommandExecutor
(ClusterTopologyProvider topologyProvider, ClusterNodeResourceProvider resourceProvider, ExceptionTranslationStrategy exceptionTranslation) Create a newClusterCommandExecutor
.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> commandCallback, Iterable<RedisClusterNode> nodes) <S,
T> ClusterCommandExecutor.MultiNodeResult<T> executeCommandOnAllNodes
(ClusterCommandExecutor.ClusterCommandCallback<S, T> commandCallback) RunClusterCommandExecutor.ClusterCommandCallback
on all reachable master nodes.executeCommandOnArbitraryNode
(ClusterCommandExecutor.ClusterCommandCallback<?, T> commandCallback) RunClusterCommandExecutor.ClusterCommandCallback
on 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.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 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 toSimpleAsyncTaskExecutor
if null.
-
-
Method Details
-
executeCommandOnArbitraryNode
public <T> ClusterCommandExecutor.NodeResult<T> executeCommandOnArbitraryNode(ClusterCommandExecutor.ClusterCommandCallback<?, T> commandCallback) RunClusterCommandExecutor.ClusterCommandCallback
on 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.NodeResult
from 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.ClusterCommandCallback
on all reachable master nodes.- Parameters:
commandCallback
- must not be null.- Returns:
- never null.
- Throws:
ClusterCommandExecutionFailureException
- if a failure occurs while executing the givencommand
on 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 givencommand
on 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.MultiKeyClusterCommandCallback
with 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 onMOVED
orASK
.- Parameters:
maxRedirects
- set to zero to suspend redirects.
-
destroy
- Specified by:
destroy
in interfaceDisposableBean
- Throws:
Exception
-