Interface StatefulRedisClusterConnection<K,V>
-
- Type Parameters:
K
- Key type.V
- Value type.
- All Superinterfaces:
AsyncCloseable
,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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
addListener(RedisClusterPushListener listener)
Add a newlistener
to consume push messages.RedisAdvancedClusterAsyncCommands<K,V>
async()
Returns theRedisAdvancedClusterAsyncCommands
API for the current connection.RedisChannelWriter
getChannelWriter()
default StatefulRedisConnection<K,V>
getConnection(String nodeId)
Retrieve a connection to the specified cluster node using thenodeId
suitable forwrite operations
.default StatefulRedisConnection<K,V>
getConnection(String host, int port)
Retrieve a connection to the specified cluster node using host and port suitable forwrite operations
.StatefulRedisConnection<K,V>
getConnection(String host, int port, ConnectionIntent connectionIntent)
Retrieve a connection to the specified cluster node using host and port.StatefulRedisConnection<K,V>
getConnection(String nodeId, ConnectionIntent connectionIntent)
Retrieve a connection to the specified cluster node using thenodeId
for the givenConnectionIntent
.default CompletableFuture<StatefulRedisConnection<K,V>>
getConnectionAsync(String nodeId)
Retrieve asynchronously a connection to the specified cluster node using thenodeId
suitable forwrite operations
.default CompletableFuture<StatefulRedisConnection<K,V>>
getConnectionAsync(String host, int port)
Retrieve asynchronously a connection to the specified cluster node using host and port suitable forwrite operations
.CompletableFuture<StatefulRedisConnection<K,V>>
getConnectionAsync(String host, int port, ConnectionIntent connectionIntent)
Retrieve asynchronously a connection to the specified cluster node using host and port for the givenConnectionIntent
.CompletableFuture<StatefulRedisConnection<K,V>>
getConnectionAsync(String nodeId, ConnectionIntent connectionIntent)
Retrieve asynchronously a connection to the specified cluster node using thenodeId
for the givenConnectionIntent
.Partitions
getPartitions()
ReadFrom
getReadFrom()
Gets theReadFrom
setting for this connection.RedisAdvancedClusterReactiveCommands<K,V>
reactive()
Returns theRedisAdvancedClusterReactiveCommands
API for the current connection.void
removeListener(RedisClusterPushListener listener)
Remove an existinglistener
.void
setReadFrom(ReadFrom readFrom)
Set from which nodes data is read.RedisAdvancedClusterCommands<K,V>
sync()
Returns theRedisAdvancedClusterCommands
API for the current connection.-
Methods inherited from interface io.lettuce.core.api.StatefulConnection
addListener, close, closeAsync, dispatch, dispatch, flushCommands, getOptions, getResources, getTimeout, isOpen, removeListener, reset, setAutoFlushCommands, setTimeout
-
-
-
-
Method Detail
-
sync
RedisAdvancedClusterCommands<K,V> sync()
Returns theRedisAdvancedClusterCommands
API for the current connection. Does not create a new connection.- Returns:
- the synchronous API for the underlying connection.
-
async
RedisAdvancedClusterAsyncCommands<K,V> async()
Returns theRedisAdvancedClusterAsyncCommands
API for the current connection. Does not create a new connection.- Returns:
- the asynchronous API for the underlying connection.
-
reactive
RedisAdvancedClusterReactiveCommands<K,V> reactive()
Returns theRedisAdvancedClusterReactiveCommands
API for the current connection. Does not create a new connection.- Returns:
- the reactive API for the underlying connection.
-
getConnection
default StatefulRedisConnection<K,V> getConnection(String nodeId)
Retrieve a connection to the specified cluster node using thenodeId
suitable forwrite operations
. 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 specifiednodeId
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
.Calling this method is equivalent to calling
getConnection(String, ConnectionIntent)
with theconnectionIntent
parameter set toConnectionIntent.WRITE
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 bynodeId
is not part of the cluster
-
getConnection
StatefulRedisConnection<K,V> getConnection(String nodeId, ConnectionIntent connectionIntent)
Retrieve a connection to the specified cluster node using thenodeId
for the givenConnectionIntent
. 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 specifiednodeId
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
.This method is intended to be used for cases where the caller requires a specific connection type (READ or WRITE) to a given node in a cluster.
In contrast to the
StatefulRedisClusterConnection
, node-connections do not route commands to other cluster nodes.- Parameters:
nodeId
- the node IdconnectionIntent
- the intent for usage of the connection.- Returns:
- a connection to the requested cluster node
- Throws:
RedisException
- if the requested node identified bynodeId
is not part of the cluster- Since:
- 6.2
-
getConnectionAsync
default CompletableFuture<StatefulRedisConnection<K,V>> getConnectionAsync(String nodeId)
Retrieve asynchronously a connection to the specified cluster node using thenodeId
suitable forwrite operations
. 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 specifiednodeId
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
.Calling this method is equivalent to calling
getConnectionAsync(String, ConnectionIntent)
with theconnectionIntent
parameter set toConnectionIntent.WRITE
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 bynodeId
is not part of the cluster- Since:
- 5.0
-
getConnectionAsync
CompletableFuture<StatefulRedisConnection<K,V>> getConnectionAsync(String nodeId, ConnectionIntent connectionIntent)
Retrieve asynchronously a connection to the specified cluster node using thenodeId
for the givenConnectionIntent
. 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 specifiednodeId
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
.This method is intended to be used for cases where the caller requires a specific connection type (READ or WRITE) to a given node in a cluster.
In contrast to the
StatefulRedisClusterConnection
, node-connections do not route commands to other cluster nodes.- Parameters:
nodeId
- the node IdconnectionIntent
- the intent for usage of the connection.- Returns:
CompletableFuture
to indicate success or failure to connect to the requested cluster node.- Throws:
RedisException
- if the requested node identified bynodeId
is not part of the cluster- Since:
- 6.2
-
getConnection
default StatefulRedisConnection<K,V> getConnection(String host, int port)
Retrieve a connection to the specified cluster node using host and port suitable forwrite operations
. This connection is bound to a host and port. Updates to the cluster topology view can close the connection once the host, identified byhost
andport
, 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()
.Calling this method is equivalent to calling
getConnection(String, int, ConnectionIntent)
with theconnectionIntent
parameter set toConnectionIntent.WRITE
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 byhost
andport
is not part of the cluster
-
getConnection
StatefulRedisConnection<K,V> getConnection(String host, int port, ConnectionIntent connectionIntent)
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 byhost
andport
, 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 portconnectionIntent
- the intent of the connection seegetConnection(String, ConnectionIntent)
- Returns:
- a connection to the requested cluster node
- Throws:
RedisException
- if the requested node identified byhost
andport
is not part of the cluster- Since:
- 6.2
-
getConnectionAsync
default CompletableFuture<StatefulRedisConnection<K,V>> getConnectionAsync(String host, int port)
Retrieve asynchronously a connection to the specified cluster node using host and port suitable forwrite operations
. This connection is bound to a host and port. Updates to the cluster topology view can close the connection once the host, identified byhost
andport
, 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()
.Calling this method is equivalent to calling
getConnectionAsync(String, int, ConnectionIntent)
with theconnectionIntent
parameter set toConnectionIntent.WRITE
In contrast to the
StatefulRedisClusterConnection
, node-connections do not route commands to other cluster nodes.- Parameters:
host
- the hostport
- the port- Returns:
CompletableFuture
to indicate success or failure to connect to the requested cluster node.- Throws:
RedisException
- if the requested node identified byhost
andport
is not part of the cluster- Since:
- 5.0
-
getConnectionAsync
CompletableFuture<StatefulRedisConnection<K,V>> getConnectionAsync(String host, int port, ConnectionIntent connectionIntent)
Retrieve asynchronously a connection to the specified cluster node using host and port for the givenConnectionIntent
. This connection is bound to a host and port. Updates to the cluster topology view can close the connection once the host, identified byhost
andport
, 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 portconnectionIntent
- the intent of the connection seegetConnection(String, ConnectionIntent)
- Returns:
CompletableFuture
to indicate success or failure to connect to the requested cluster node.- Throws:
RedisException
- if the requested node identified byhost
andport
is not part of the cluster- Since:
- 6.2
-
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 forReadFrom
for more information.- Parameters:
readFrom
- the read from setting, must not benull
-
getReadFrom
ReadFrom getReadFrom()
Gets theReadFrom
setting for this connection. Defaults toReadFrom.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 newlistener
to consume push messages.- Parameters:
listener
- the listener, must not benull
.- Since:
- 6.0
-
removeListener
void removeListener(RedisClusterPushListener listener)
Remove an existinglistener
.- Parameters:
listener
- the listener, must not benull
.- Since:
- 6.0
-
-