Module lettuce.core
Package io.lettuce.core.cluster.api
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 Summary
Modifier and Type Method Description voidaddListener(RedisClusterPushListener listener)Add a newlistenerto consume push messages.RedisAdvancedClusterAsyncCommands<K,V>async()Returns theRedisAdvancedClusterAsyncCommandsAPI for the current connection.RedisChannelWritergetChannelWriter()StatefulRedisConnection<K,V>getConnection(String nodeId)Retrieve a connection to the specified cluster node using the nodeId.StatefulRedisConnection<K,V>getConnection(String host, int port)Retrieve a connection to the specified cluster node using host and port.CompletableFuture<StatefulRedisConnection<K,V>>getConnectionAsync(String nodeId)Retrieve asynchronously a connection to the specified cluster node using the nodeId.CompletableFuture<StatefulRedisConnection<K,V>>getConnectionAsync(String host, int port)Retrieve asynchronously a connection to the specified cluster node using host and port.PartitionsgetPartitions()ReadFromgetReadFrom()Gets theReadFromsetting for this connection.RedisAdvancedClusterReactiveCommands<K,V>reactive()Returns theRedisAdvancedClusterReactiveCommandsAPI for the current connection.voidremoveListener(RedisClusterPushListener listener)Remove an existinglistener.voidsetReadFrom(ReadFrom readFrom)Set from which nodes data is read.RedisAdvancedClusterCommands<K,V>sync()Returns theRedisAdvancedClusterCommandsAPI for the current connection.Methods inherited from interface io.lettuce.core.api.StatefulConnection
close, closeAsync, dispatch, dispatch, flushCommands, getOptions, getResources, getTimeout, isOpen, reset, setAutoFlushCommands, setTimeout
-
Method Details
-
sync
RedisAdvancedClusterCommands<K,V> sync()Returns theRedisAdvancedClusterCommandsAPI for the current connection. Does not create a new connection.- Returns:
- the synchronous API for the underlying connection.
-
async
RedisAdvancedClusterAsyncCommands<K,V> async()Returns theRedisAdvancedClusterAsyncCommandsAPI for the current connection. Does not create a new connection.- Returns:
- the asynchronous API for the underlying connection.
-
reactive
RedisAdvancedClusterReactiveCommands<K,V> reactive()Returns theRedisAdvancedClusterReactiveCommandsAPI for the current connection. Does not create a new connection.- Returns:
- the reactive API for the underlying connection.
-
getConnection
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 specifiednodeId, that behavior can also lead to a closed connection once the node with the specifiednodeIdis 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 inPartitions. In contrast to theStatefulRedisClusterConnection, 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 bynodeIdis not part of the cluster
-
getConnectionAsync
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 specifiednodeId, that behavior can also lead to a closed connection once the node with the specifiednodeIdis 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 inPartitions. In contrast to theStatefulRedisClusterConnection, node-connections do not route commands to other cluster nodes.- Parameters:
nodeId- the node Id- Returns:
CompletableFutureto indicate success or failure to connect to the requested cluster node.- Throws:
RedisException- if the requested node identified bynodeIdis not part of the cluster- Since:
- 5.0
-
getConnection
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 byhostandport, 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 hostport- the port- Returns:
- a connection to the requested cluster node
- Throws:
RedisException- if the requested node identified byhostandportis not part of the cluster
-
getConnectionAsync
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 byhostandport, 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 hostport- the port- Returns:
CompletableFutureto indicate success or failure to connect to the requested cluster node.- Throws:
RedisException- if the requested node identified byhostandportis not part of the cluster- Since:
- 5.0
-
setReadFrom
Set from which nodes data is read. The setting is used as default for read operations on this connection. See the documentation forReadFromfor more information.- Parameters:
readFrom- the read from setting, must not benull
-
getReadFrom
ReadFrom getReadFrom()Gets theReadFromsetting for this connection. Defaults toReadFrom.UPSTREAMif not set.- Returns:
- the read from setting
-
getPartitions
Partitions getPartitions()- Returns:
- Known partitions for this connection.
-
getChannelWriter
RedisChannelWriter getChannelWriter()- Returns:
- the underlying
RedisChannelWriter.
-
addListener
Add a newlistenerto consume push messages.- Parameters:
listener- the listener, must not benull.- Since:
- 6.0
-
removeListener
Remove an existinglistener.- Parameters:
listener- the listener, must not benull.- Since:
- 6.0
-