Module lettuce.core

Interface StatefulRedisClusterConnection<K,​V>

Type Parameters:
K - Key type.
V - Value type.
All Superinterfaces:
AsyncCloseable, AutoCloseable, StatefulConnection<K,​V>
All Known Implementing Classes:
StatefulRedisClusterConnectionImpl

public interface StatefulRedisClusterConnection<K,​V>
extends StatefulConnection<K,​V>
A stateful cluster connection. Advanced cluster connections provide transparent command routing based on the first command key.
Since:
4.0
Author:
Mark Paluch
  • Method Details

    • sync

      Returns the RedisAdvancedClusterCommands API for the current connection. Does not create a new connection.
      Returns:
      the synchronous API for the underlying connection.
    • async

      Returns the RedisAdvancedClusterAsyncCommands API for the current connection. Does not create a new connection.
      Returns:
      the asynchronous API for the underlying connection.
    • reactive

      Returns the RedisAdvancedClusterReactiveCommands API for the current connection. Does not create a new connection.
      Returns:
      the reactive API for the underlying connection.
    • getConnection

      StatefulRedisConnection<K,​V> getConnection​(String nodeId)
      Retrieve a connection to the specified cluster node using the nodeId. Host and port are looked up in the node list. This connection is bound to the node id. Once the cluster topology view is updated, the connection will try to reconnect the to the node with the specified nodeId, that behavior can also lead to a closed connection once the node with the specified nodeId is no longer part of the cluster. Do not close the connections. Otherwise, unpredictable behavior will occur. The nodeId must be part of the cluster and is validated against the current topology view in Partitions. In contrast to the StatefulRedisClusterConnection, node-connections do not route commands to other cluster nodes.
      Parameters:
      nodeId - the node Id
      Returns:
      a connection to the requested cluster node
      Throws:
      RedisException - if the requested node identified by nodeId is not part of the cluster
    • getConnectionAsync

      CompletableFuture<StatefulRedisConnection<K,​V>> getConnectionAsync​(String nodeId)
      Retrieve asynchronously a connection to the specified cluster node using the nodeId. Host and port are looked up in the node list. This connection is bound to the node id. Once the cluster topology view is updated, the connection will try to reconnect the to the node with the specified nodeId, that behavior can also lead to a closed connection once the node with the specified nodeId is no longer part of the cluster. Do not close the connections. Otherwise, unpredictable behavior will occur. The nodeId must be part of the cluster and is validated against the current topology view in Partitions. In contrast to the StatefulRedisClusterConnection, node-connections do not route commands to other cluster nodes.
      Parameters:
      nodeId - the node Id
      Returns:
      CompletableFuture to indicate success or failure to connect to the requested cluster node.
      Throws:
      RedisException - if the requested node identified by nodeId is not part of the cluster
      Since:
      5.0
    • getConnection

      StatefulRedisConnection<K,​V> getConnection​(String host, int port)
      Retrieve a connection to the specified cluster node using host and port. This connection is bound to a host and port. Updates to the cluster topology view can close the connection once the host, identified by host and port, are no longer part of the cluster.

      Do not close the connections. Otherwise, unpredictable behavior will occur. Host and port connections are verified by default for cluster membership, see ClusterClientOptions.isValidateClusterNodeMembership().

      In contrast to the StatefulRedisClusterConnection, node-connections do not route commands to other cluster nodes.

      Parameters:
      host - the host
      port - the port
      Returns:
      a connection to the requested cluster node
      Throws:
      RedisException - if the requested node identified by host and port is not part of the cluster
    • getConnectionAsync

      CompletableFuture<StatefulRedisConnection<K,​V>> getConnectionAsync​(String host, int port)
      Retrieve asynchronously a connection to the specified cluster node using host and port. This connection is bound to a host and port. Updates to the cluster topology view can close the connection once the host, identified by host and port, are no longer part of the cluster.

      Do not close the connections. Otherwise, unpredictable behavior will occur. Host and port connections are verified by default for cluster membership, see ClusterClientOptions.isValidateClusterNodeMembership().

      In contrast to the StatefulRedisClusterConnection, node-connections do not route commands to other cluster nodes.

      Parameters:
      host - the host
      port - the port
      Returns:
      CompletableFuture to indicate success or failure to connect to the requested cluster node.
      Throws:
      RedisException - if the requested node identified by host and port is not part of the cluster
      Since:
      5.0
    • setReadFrom

      void setReadFrom​(ReadFrom readFrom)
      Set from which nodes data is read. The setting is used as default for read operations on this connection. See the documentation for ReadFrom for more information.
      Parameters:
      readFrom - the read from setting, must not be null
    • getReadFrom

      ReadFrom getReadFrom()
      Gets the ReadFrom setting for this connection. Defaults to ReadFrom.UPSTREAM if not set.
      Returns:
      the read from setting
    • getPartitions

      Partitions getPartitions()
      Returns:
      Known partitions for this connection.
    • getChannelWriter

      RedisChannelWriter getChannelWriter()
      Returns:
      the underlying RedisChannelWriter.
    • addListener

      void addListener​(RedisClusterPushListener listener)
      Add a new listener to consume push messages.
      Parameters:
      listener - the listener, must not be null.
      Since:
      6.0
    • removeListener

      void removeListener​(RedisClusterPushListener listener)
      Remove an existing listener.
      Parameters:
      listener - the listener, must not be null.
      Since:
      6.0