public class StatefulRedisClusterConnectionImpl<K,V> extends RedisChannelHandler<K,V> implements StatefulRedisClusterConnection<K,V>
StatefulRedisClusterConnectionImpl
A ConnectionWatchdog monitors each connection and reconnects automatically until RedisChannelHandler.close() is called. All
pending commands will be (re)sent after successful reconnection.| Modifier and Type | Field and Description |
|---|---|
protected RedisAdvancedClusterAsyncCommandsImpl<K,V> |
async |
protected RedisCodec<K,V> |
codec |
protected RedisAdvancedClusterReactiveCommandsImpl<K,V> |
reactive |
protected RedisAdvancedClusterCommands<K,V> |
sync |
| Constructor and Description |
|---|
StatefulRedisClusterConnectionImpl(RedisChannelWriter writer,
ClusterPushHandler pushHandler,
RedisCodec<K,V> codec,
Duration timeout)
Initialize a new connection.
|
| Modifier and Type | Method and Description |
|---|---|
void |
activated()
Notification when the connection becomes active (connected).
|
void |
addListener(RedisClusterPushListener listener)
Add a new
listener to consume push messages. |
RedisAdvancedClusterAsyncCommands<K,V> |
async()
Returns the
RedisAdvancedClusterAsyncCommands API for the current connection. |
protected <T> T |
clusterSyncHandler(Class<?>... interfaces) |
Collection<RedisCommand<K,V,?>> |
dispatch(Collection<? extends RedisCommand<K,V,?>> commands)
Dispatch multiple command in a single write on the channel.
|
<T> RedisCommand<K,V,T> |
dispatch(RedisCommand<K,V,T> command)
Dispatch a command.
|
StatefulRedisConnection<K,V> |
getConnection(String nodeId,
ConnectionIntent connectionIntent)
Retrieve a connection to the specified cluster node using the
nodeId for the given ConnectionIntent. |
StatefulRedisConnection<K,V> |
getConnection(String host,
int port,
ConnectionIntent connectionIntent)
Retrieve a connection to the specified cluster node using host and port.
|
CompletableFuture<StatefulRedisConnection<K,V>> |
getConnectionAsync(String nodeId,
ConnectionIntent connectionIntent)
Retrieve asynchronously a connection to the specified cluster node using the
nodeId for the given
ConnectionIntent. |
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 given
ConnectionIntent. |
Partitions |
getPartitions() |
ReadFrom |
getReadFrom()
Gets the
ReadFrom setting for this connection. |
protected RedisAdvancedClusterAsyncCommandsImpl<K,V> |
newRedisAdvancedClusterAsyncCommandsImpl() |
protected RedisAdvancedClusterCommands<K,V> |
newRedisAdvancedClusterCommandsImpl() |
protected RedisAdvancedClusterReactiveCommandsImpl<K,V> |
newRedisAdvancedClusterReactiveCommandsImpl() |
RedisAdvancedClusterReactiveCommands<K,V> |
reactive()
Returns the
RedisAdvancedClusterReactiveCommands API for the current connection. |
void |
removeListener(RedisClusterPushListener listener)
Remove an existing
listener. |
void |
setPartitions(Partitions partitions) |
void |
setReadFrom(ReadFrom readFrom)
Set from which nodes data is read.
|
RedisAdvancedClusterCommands<K,V> |
sync()
Returns the
RedisAdvancedClusterCommands API for the current connection. |
protected InvocationHandler |
syncInvocationHandler() |
addListener, addListener, close, closeAsync, deactivated, flushCommands, getChannelWriter, getConnectionEvents, getOptions, getResources, getTimeout, isClosed, isOpen, registerCloseables, removeListener, reset, setAutoFlushCommands, setOptions, setTimeout, syncHandlerclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetChannelWriter, getConnection, getConnection, getConnectionAsync, getConnectionAsyncaddListener, close, closeAsync, flushCommands, getOptions, getResources, getTimeout, isOpen, removeListener, reset, setAutoFlushCommands, setTimeoutprotected final RedisCodec<K,V> codec
protected final RedisAdvancedClusterCommands<K,V> sync
protected final RedisAdvancedClusterAsyncCommandsImpl<K,V> async
protected final RedisAdvancedClusterReactiveCommandsImpl<K,V> reactive
public StatefulRedisClusterConnectionImpl(RedisChannelWriter writer, ClusterPushHandler pushHandler, RedisCodec<K,V> codec, Duration timeout)
writer - the channel writerpushHandler - the Cluster push handlercodec - Codec used to encode/decode keys and values.timeout - Maximum time to wait for a response.protected RedisAdvancedClusterReactiveCommandsImpl<K,V> newRedisAdvancedClusterReactiveCommandsImpl()
protected RedisAdvancedClusterCommands<K,V> newRedisAdvancedClusterCommandsImpl()
protected <T> T clusterSyncHandler(Class<?>... interfaces)
protected RedisAdvancedClusterAsyncCommandsImpl<K,V> newRedisAdvancedClusterAsyncCommandsImpl()
public RedisAdvancedClusterCommands<K,V> sync()
StatefulRedisClusterConnectionRedisAdvancedClusterCommands API for the current connection. Does not create a new connection.sync in interface StatefulRedisClusterConnection<K,V>protected InvocationHandler syncInvocationHandler()
public RedisAdvancedClusterAsyncCommands<K,V> async()
StatefulRedisClusterConnectionRedisAdvancedClusterAsyncCommands API for the current connection. Does not create a new connection.async in interface StatefulRedisClusterConnection<K,V>public RedisAdvancedClusterReactiveCommands<K,V> reactive()
StatefulRedisClusterConnectionRedisAdvancedClusterReactiveCommands API for the current connection. Does not create a new
connection.reactive in interface StatefulRedisClusterConnection<K,V>public void addListener(RedisClusterPushListener listener)
StatefulRedisClusterConnectionlistener to consume push messages.addListener in interface StatefulRedisClusterConnection<K,V>listener - the listener, must not be null.public void removeListener(RedisClusterPushListener listener)
StatefulRedisClusterConnectionlistener.removeListener in interface StatefulRedisClusterConnection<K,V>listener - the listener, must not be null.public StatefulRedisConnection<K,V> getConnection(String nodeId, ConnectionIntent connectionIntent)
StatefulRedisClusterConnectionnodeId for the given ConnectionIntent. 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.
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.
getConnection in interface StatefulRedisClusterConnection<K,V>nodeId - the node IdconnectionIntent - the intent for usage of the connection.public CompletableFuture<StatefulRedisConnection<K,V>> getConnectionAsync(String nodeId, ConnectionIntent connectionIntent)
StatefulRedisClusterConnectionnodeId for the given
ConnectionIntent. 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.
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.
getConnectionAsync in interface StatefulRedisClusterConnection<K,V>nodeId - the node IdconnectionIntent - the intent for usage of the connection.CompletableFuture to indicate success or failure to connect to the requested cluster node.public StatefulRedisConnection<K,V> getConnection(String host, int port, ConnectionIntent connectionIntent)
StatefulRedisClusterConnectionhost 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.
getConnection in interface StatefulRedisClusterConnection<K,V>host - the hostport - the portconnectionIntent - the intent of the connection see StatefulRedisClusterConnection.getConnection(String, ConnectionIntent)public CompletableFuture<StatefulRedisConnection<K,V>> getConnectionAsync(String host, int port, ConnectionIntent connectionIntent)
StatefulRedisClusterConnectionConnectionIntent. 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.
getConnectionAsync in interface StatefulRedisClusterConnection<K,V>host - the hostport - the portconnectionIntent - the intent of the connection see StatefulRedisClusterConnection.getConnection(String, ConnectionIntent)CompletableFuture to indicate success or failure to connect to the requested cluster node.public void activated()
RedisChannelHandleractivated in interface ConnectionFacadeactivated in class RedisChannelHandler<K,V>public <T> RedisCommand<K,V,T> dispatch(RedisCommand<K,V,T> command)
StatefulConnectiondispatch in interface StatefulConnection<K,V>dispatch in class RedisChannelHandler<K,V>T - result typecommand - the Redis command.public Collection<RedisCommand<K,V,?>> dispatch(Collection<? extends RedisCommand<K,V,?>> commands)
StatefulConnectiondispatch in interface StatefulConnection<K,V>dispatch in class RedisChannelHandler<K,V>commands - the Redis commands.public void setPartitions(Partitions partitions)
public Partitions getPartitions()
getPartitions in interface StatefulRedisClusterConnection<K,V>public void setReadFrom(ReadFrom readFrom)
StatefulRedisClusterConnectionReadFrom for more information.setReadFrom in interface StatefulRedisClusterConnection<K,V>readFrom - the read from setting, must not be nullpublic ReadFrom getReadFrom()
StatefulRedisClusterConnectionReadFrom setting for this connection. Defaults to ReadFrom.UPSTREAM if not set.getReadFrom in interface StatefulRedisClusterConnection<K,V>Copyright © 2023 lettuce.io. All rights reserved.