public abstract class AbstractRedisClient extends Object
ClientOptions and the basic connection procedure. This
class creates the netty EventLoopGroups for NIO (NioEventLoopGroup) and EPoll (
EpollEventLoopGroup) with a default of Runtime.getRuntime().availableProcessors() * 4
threads. Reuse the instance as much as possible since the EventLoopGroup instances are expensive and can consume a
huge part of your resources, if you create multiple instances.
You can set the number of threads per NioEventLoopGroup by setting the io.netty.eventLoopThreads system
property to a reasonable number of threads.
ClientResources| Modifier and Type | Field and Description |
|---|---|
protected ChannelGroup |
channels |
protected Set<Closeable> |
closeableResources |
protected ConnectionEvents |
connectionEvents |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractRedisClient(ClientResources clientResources)
Create a new instance with client resources.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(RedisConnectionStateListener listener)
Add a listener for the RedisConnectionState.
|
protected void |
channelType(ConnectionBuilder connectionBuilder,
ConnectionPoint connectionPoint) |
protected void |
connectionBuilder(Mono<SocketAddress> socketAddressSupplier,
ConnectionBuilder connectionBuilder,
RedisURI redisURI)
Populate connection builder with necessary resources.
|
protected io.lettuce.core.RedisHandshake |
createHandshake(ConnectionState state) |
protected int |
getChannelCount() |
protected <T> T |
getConnection(CompletableFuture<T> connectionFuture)
Retrieve the connection from
ConnectionFuture. |
protected <T> T |
getConnection(ConnectionFuture<T> connectionFuture)
Retrieve the connection from
ConnectionFuture. |
Duration |
getDefaultTimeout()
Returns the default
timeout for commands. |
ClientOptions |
getOptions()
Returns the
ClientOptions which are valid for that client. |
protected int |
getResourceCount() |
ClientResources |
getResources()
Returns the
ClientResources which are used with that client. |
protected <K,V,T extends RedisChannelHandler<K,V>> |
initializeChannelAsync(ConnectionBuilder connectionBuilder)
Connect and initialize a channel from
ConnectionBuilder. |
void |
removeListener(RedisConnectionStateListener listener)
Removes a listener.
|
void |
setDefaultTimeout(Duration timeout)
Set the default timeout for connections created by this client.
|
void |
setDefaultTimeout(long timeout,
TimeUnit unit)
Deprecated.
since 5.0, use
setDefaultTimeout(Duration). |
protected void |
setOptions(ClientOptions clientOptions)
Set the
ClientOptions for the client. |
void |
shutdown()
Shutdown this client and close all open connections once this method is called.
|
void |
shutdown(Duration quietPeriod,
Duration timeout)
Shutdown this client and close all open connections once this method is called.
|
void |
shutdown(long quietPeriod,
long timeout,
TimeUnit timeUnit)
Shutdown this client and close all open connections once this method is called.
|
CompletableFuture<Void> |
shutdownAsync()
Shutdown this client and close all open connections asynchronously.
|
CompletableFuture<Void> |
shutdownAsync(long quietPeriod,
long timeout,
TimeUnit timeUnit)
Shutdown this client and close all open connections asynchronously.
|
protected final ConnectionEvents connectionEvents
protected final ChannelGroup channels
protected AbstractRedisClient(ClientResources clientResources)
clientResources - the client resources. If null, the client will create a new dedicated instance of
client resources and keep track of them.protected int getChannelCount()
public Duration getDefaultTimeout()
timeout for commands.timeout for commands.public void setDefaultTimeout(Duration timeout)
timeout - default connection timeout, must not be null.@Deprecated public void setDefaultTimeout(long timeout, TimeUnit unit)
setDefaultTimeout(Duration).timeout - Default connection timeout.unit - Unit of time for the timeout.public ClientOptions getOptions()
ClientOptions which are valid for that client. Connections inherit the current options at the moment
the connection is created. Changes to options will not affect existing connections.ClientOptions for this clientprotected void setOptions(ClientOptions clientOptions)
ClientOptions for the client.clientOptions - client options for the client and connections that are created after setting the optionspublic ClientResources getResources()
ClientResources which are used with that client.ClientResources for this client.protected int getResourceCount()
public void addListener(RedisConnectionStateListener listener)
listener - must not be nullpublic void removeListener(RedisConnectionStateListener listener)
listener - must not be nullprotected void connectionBuilder(Mono<SocketAddress> socketAddressSupplier, ConnectionBuilder connectionBuilder, RedisURI redisURI)
socketAddressSupplier - address supplier for initial connect and re-connectconnectionBuilder - connection builder to configure the connectionredisURI - URI of the Redis instanceprotected void channelType(ConnectionBuilder connectionBuilder, ConnectionPoint connectionPoint)
protected <T> T getConnection(ConnectionFuture<T> connectionFuture)
ConnectionFuture. Performs a blocking ConnectionFuture.get() to synchronize
the channel/connection initialization. Any exception is rethrown as RedisConnectionException.T - Connection type.connectionFuture - must not be null.RedisConnectionException - in case of connection failures.protected <T> T getConnection(CompletableFuture<T> connectionFuture)
ConnectionFuture. Performs a blocking ConnectionFuture.get() to synchronize
the channel/connection initialization. Any exception is rethrown as RedisConnectionException.T - Connection type.connectionFuture - must not be null.RedisConnectionException - in case of connection failures.protected <K,V,T extends RedisChannelHandler<K,V>> ConnectionFuture<T> initializeChannelAsync(ConnectionBuilder connectionBuilder)
ConnectionBuilder.connectionBuilder - must not be null.ConnectionFuture to synchronize the connection process.public void shutdown()
ClientResources are shut down/released gracefully considering quiet time and the shutdown timeout. The
client should be discarded after calling shutdown. The shutdown is executed without quiet time and a timeout of 2
TimeUnit.SECONDS.public void shutdown(Duration quietPeriod, Duration timeout)
ClientResources are shut down/released gracefully considering quiet time and the shutdown timeout. The
client should be discarded after calling shutdown.quietPeriod - the quiet period to allow the executor gracefully shut down.timeout - the maximum amount of time to wait until the backing executor is shutdown regardless if a task was
submitted during the quiet period.EventExecutorGroup.shutdownGracefully(long, long, TimeUnit)public void shutdown(long quietPeriod,
long timeout,
TimeUnit timeUnit)
ClientResources are shut down/released gracefully considering quiet time and the shutdown timeout. The
client should be discarded after calling shutdown.quietPeriod - the quiet period to allow the executor gracefully shut down.timeout - the maximum amount of time to wait until the backing executor is shutdown regardless if a task was
submitted during the quiet period.timeUnit - the unit of quietPeriod and timeout.EventExecutorGroup.shutdownGracefully(long, long, TimeUnit)public CompletableFuture<Void> shutdownAsync()
ClientResources are shut down/released gracefully considering quiet time and the shutdown timeout. The client
should be discarded after calling shutdown. The shutdown is executed without quiet time and a timeout of 2
TimeUnit.SECONDS.EventExecutorGroup.shutdownGracefully(long, long, TimeUnit)public CompletableFuture<Void> shutdownAsync(long quietPeriod, long timeout, TimeUnit timeUnit)
ClientResources are shut down/released gracefully considering quiet time and the shutdown timeout. The client
should be discarded after calling shutdown.quietPeriod - the quiet period to allow the executor gracefully shut down.timeout - the maximum amount of time to wait until the backing executor is shutdown regardless if a task was
submitted during the quiet period.timeUnit - the unit of quietPeriod and timeout.EventExecutorGroup.shutdownGracefully(long, long, TimeUnit)protected io.lettuce.core.RedisHandshake createHandshake(ConnectionState state)
Copyright © 2021 lettuce.io. All rights reserved.