final class RedisClusterClient extends RedisKeyedExecutor with Closeable
Redis client implementation for Redis Cluster deployments. Internally, it uses single RedisNodeClient instance for every known master in the cluster plus a separate connection for monitoring of every known master. RedisNodeClient instances are dynamically created and destroyed as the cluster changes its state.
The cluster client is only able to execute commands or transactions containing keys which determine which master should be contacted. However, it's possible to gain access to RedisNodeClient instances that RedisClusterClient internally uses to connect to every master (see ClusterState and masterClient).
RedisClusterClient can directly execute only RedisBatches. It automatically distributes every batch over multiple cluster masters and handles cluster redirections if necessary. See executeBatch for more details.
RedisClusterClient cannot directly execute RedisOps (e.g. WATCH
-MULTI
-EXEC
transactions).
You must manually access node client for appropriate master through currentState and execute the operation using it.
However, be aware that you must manually handle cluster redirections and cluster state changes while doing so.
- Alphabetic
- By Inheritance
- RedisClusterClient
- Closeable
- AutoCloseable
- RedisKeyedExecutor
- RedisExecutor
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
RedisClusterClient(seedNodes: Seq[NodeAddress] = List(NodeAddress.Default), config: ClusterConfig = ClusterConfig())(implicit system: ActorSystem)
- seedNodes
nodes used to fetch initial cluster state from. You don't need to list all cluster nodes, it is only required that at least one of the seed nodes is available during startup.
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
close(): Unit
- Definition Classes
- RedisClusterClient → Closeable → AutoCloseable
- val config: ClusterConfig
-
def
currentState: ClusterState
Returns currently known cluster state.
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
executeBatch[A](batch: RedisBatch[A], config: ExecutionConfig): commons.Future[A]
Executes a RedisBatch on a Redis Cluster deployment.
Executes a RedisBatch on a Redis Cluster deployment. In order to determine node on which each command must be executed, every command or
MULTI
-EXEC
transaction in the batch must contain at least one key. Also, in the scope of a single command or transaction all keys must hash to the same slot.However, each command or transaction in the batch may target different slot. RedisClusterClient automatically splits the original batch and creates smaller batches, one for every master node that needs to be contacted. In other words, commands and transactions from the original batch are automatically distributed over Redis Cluster master nodes, in parallel, using a scatter-gather like manner.
RedisClusterClient also automatically retries execution of commands that fail due to cluster redirections (MOVED and ASK), cluster state changes and
TRYAGAIN
errors which might be returned for multikey commands during slot migration. See Redis Cluster specification for more detailed information on redirections and migrations. Redirection andTRYAGAIN
handling is configured by retry strategies in config.ClusterConfig.In general, you can assume that if there are no redirections involved, commands executed on the same master node are executed in the same order as specified in the original batch.
Execution of each command in the batch or the whole batch may fail due to following reasons:
- NoKeysException when some command or transaction contains no keys
- CrossSlotException when some command or transaction contains keys hashing to different slots
- ForbiddenCommandException when trying to execute command not supported by this client type
- ErrorReplyException when Redis server replies with an error for some command
- UnexpectedReplyException when Redis server replies with something unexpected by a decoder of some command
- ConnectionClosedException when connection is closed or reset (the client reconnects automatically after connection failure but commands that were in the middle of execution may still fail)
- WriteFailedException when a network write failed
- TooManyRedirectionsException when
a command was replied with
MOVED
orASK
redirection too many times in a row. This might indicate misconfiguration of the Redis Cluster deployment.
- Definition Classes
- RedisClusterClient → RedisExecutor
-
def
executionContext: commons.ExecutionContext
- Definition Classes
- RedisClusterClient → RedisExecutor
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
initialized: commons.Future[RedisClusterClient.this.type]
Waits until cluster state is known and RedisNodeClient for every master node is initialized.
-
def
initializedCurrentState: commons.Future[ClusterState]
Returns currently known cluster state, waiting for initialization if necessary.
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
masterClient(address: NodeAddress): commons.Future[RedisNodeClient]
Returns a RedisNodeClient internally used to connect to a master with given address.
Returns a RedisNodeClient internally used to connect to a master with given address. Note that the address may belong to a master that is not yet known to this cluster client. In such case, node client for this master will be created on demand. However, be aware that this temporary client will be immediately closed if it's master is not listed in next cluster state fetched by RedisClusterClient. Therefore, you can't use this method to obtain clients for arbitrary nodes - only for master nodes that this cluster client knows or is about to know upon next state refresh.
This method is primarily intended to be used when having to manually recover from a cluster redirection. If you want to obtain node client serving particular hash slot, get it from currentState.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- val seedNodes: Seq[NodeAddress]
-
def
setStateListener(listener: (ClusterState) ⇒ Unit)(implicit executor: commons.ExecutionContext): Unit
Sets a listener that is notified every time RedisClusterClient detects a change in cluster state (slot mapping).
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )