Packages

c

com.avsystem.commons.redis

RedisClusterClient

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.

Linear Supertypes
Closeable, AutoCloseable, RedisKeyedExecutor, RedisExecutor, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. RedisClusterClient
  2. Closeable
  3. AutoCloseable
  4. RedisKeyedExecutor
  5. RedisExecutor
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. 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

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  6. def close(): Unit
    Definition Classes
    RedisClusterClient → Closeable → AutoCloseable
  7. val config: ClusterConfig
  8. def currentState: ClusterState

    Returns currently known cluster state.

  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  11. 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) and cluster state changes. However, remember that multi-key commands may still fail with TRYAGAIN error during resharding of the slot targeted by the multi-key operation. (see Redis Cluster specification). RedisClusterClient makes no attempt to recover from these errors. It would require waiting for an indeterminate time until the migration is finished. The maximum number of consecutive retries caused by redirections is configured by maxRedirections. See Redis Cluster specification for more detailed information on redirections.

    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:

    Definition Classes
    RedisClusterClientRedisExecutor
  12. def executionContext: commons.ExecutionContext
    Definition Classes
    RedisClusterClientRedisExecutor
  13. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  16. def initialized: commons.Future[RedisClusterClient.this.type]

    Waits until cluster state is known and RedisNodeClient for every master node is initialized.

  17. def initializedCurrentState: commons.Future[ClusterState]

    Returns currently known cluster state, waiting for initialization if necessary.

  18. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  19. 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.

  20. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  23. val seedNodes: Seq[NodeAddress]
  24. 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).

  25. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  26. def toString(): String
    Definition Classes
    AnyRef → Any
  27. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from Closeable

Inherited from AutoCloseable

Inherited from RedisKeyedExecutor

Inherited from RedisExecutor

Inherited from AnyRef

Inherited from Any

Ungrouped