@ChannelHandler.Sharable 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.ChannelHandler.Sharable
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 |
timeout, unit
Constructor and Description |
---|
StatefulRedisClusterConnectionImpl(RedisChannelWriter<K,V> writer,
RedisCodec<K,V> codec,
long timeout,
TimeUnit unit)
Initialize a new connection.
|
Modifier and Type | Method and Description |
---|---|
void |
activated()
Notification when the connection becomes active (connected).
|
RedisAdvancedClusterAsyncCommands<K,V> |
async()
Returns the
RedisAdvancedClusterAsyncCommands API for the current connection. |
<T,C extends RedisCommand<K,V,T>> |
dispatch(C command)
Dispatch a command.
|
com.lambdaworks.redis.cluster.ClusterDistributionChannelWriter<K,V> |
getClusterDistributionChannelWriter() |
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.
|
Partitions |
getPartitions() |
protected RedisAdvancedClusterReactiveCommandsImpl<K,V> |
getReactiveCommands()
Deprecated.
|
ReadFrom |
getReadFrom()
Gets the
ReadFrom setting for this connection. |
RedisAdvancedClusterReactiveCommands<K,V> |
reactive()
Returns the
RedisAdvancedClusterReactiveCommands API for the current connection. |
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, channelRead, channelRead, channelRegistered, close, deactivated, flushCommands, getChannelWriter, getOptions, getTimeout, getTimeoutUnit, isClosed, isOpen, registerCloseables, reset, setAutoFlushCommands, setOptions, setTimeout, syncHandler
channelActive, channelInactive, channelReadComplete, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, flushCommands, getOptions, getTimeout, getTimeoutUnit, isOpen, reset, setAutoFlushCommands, setTimeout
handlerAdded, handlerRemoved
protected 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<K,V> writer, RedisCodec<K,V> codec, long timeout, TimeUnit unit)
writer
- the channel writercodec
- Codec used to encode/decode keys and values.timeout
- Maximum time to wait for a response.unit
- Unit of time for the timeout.public RedisAdvancedClusterCommands<K,V> sync()
StatefulRedisClusterConnection
RedisAdvancedClusterCommands
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()
StatefulRedisClusterConnection
RedisAdvancedClusterAsyncCommands
API for the current connection. Does not create a new connection.async
in interface StatefulRedisClusterConnection<K,V>
public RedisAdvancedClusterReactiveCommands<K,V> reactive()
StatefulRedisClusterConnection
RedisAdvancedClusterReactiveCommands
API for the current connection. Does not create a new
connection.reactive
in interface StatefulRedisClusterConnection<K,V>
@Deprecated protected RedisAdvancedClusterReactiveCommandsImpl<K,V> getReactiveCommands()
public StatefulRedisConnection<K,V> getConnection(String nodeId)
StatefulRedisClusterConnection
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.getConnection
in interface StatefulRedisClusterConnection<K,V>
nodeId
- the node Idpublic StatefulRedisConnection<K,V> getConnection(String host, int port)
StatefulRedisClusterConnection
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.getConnection
in interface StatefulRedisClusterConnection<K,V>
host
- the hostport
- the portpublic com.lambdaworks.redis.cluster.ClusterDistributionChannelWriter<K,V> getClusterDistributionChannelWriter()
public void activated()
RedisChannelHandler
activated
in class RedisChannelHandler<K,V>
public <T,C extends RedisCommand<K,V,T>> C dispatch(C command)
StatefulConnection
dispatch
in interface StatefulConnection<K,V>
dispatch
in class RedisChannelHandler<K,V>
T
- result typeC
- command typecommand
- the Redis commandpublic void setPartitions(Partitions partitions)
public Partitions getPartitions()
getPartitions
in interface StatefulRedisClusterConnection<K,V>
public void setReadFrom(ReadFrom readFrom)
StatefulRedisClusterConnection
ReadFrom
for more information.setReadFrom
in interface StatefulRedisClusterConnection<K,V>
readFrom
- the read from setting, must not be nullpublic ReadFrom getReadFrom()
StatefulRedisClusterConnection
ReadFrom
setting for this connection. Defaults to ReadFrom.MASTER
if not set.getReadFrom
in interface StatefulRedisClusterConnection<K,V>
Copyright © 2018 lettuce.io. All rights reserved.