public abstract class AbstractRedisClient extends Object implements AutoCloseable
ClientOptions and the basic connection procedure. This
class creates different Netty EventLoopGroups depending on the Transports.NativeTransports used.
You can set the number of threads by using the ClientResources configuration. For more details, check the
documentation of the DefaultClientResources class.
ClientResources,
DefaultClientResources| 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(CommandListener listener)
Add a listener for Redis Command events.
|
void |
addListener(RedisConnectionStateListener listener)
Add a listener for the RedisConnectionState.
|
protected void |
channelType(ConnectionBuilder connectionBuilder,
ConnectionPoint connectionPoint) |
void |
close() |
protected void |
connectionBuilder(Mono<SocketAddress> socketAddressSupplier,
ConnectionBuilder connectionBuilder,
ConnectionEvents connectionEvents,
RedisURI redisURI)
Populate connection builder with necessary resources.
|
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 List<CommandListener> |
getCommandListeners() |
protected <T> T |
getConnection(CompletableFuture<T> connectionFuture)
Retrieve the connection from
ConnectionFuture. |
protected <T> T |
getConnection(ConnectionFuture<T> connectionFuture)
Retrieve the connection from
ConnectionFuture. |
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(CommandListener listener)
Removes a listener.
|
void |
removeListener(RedisConnectionStateListener listener)
Removes a listener.
|
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 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 null.public void removeListener(RedisConnectionStateListener listener)
listener - must not be null.public void addListener(CommandListener listener)
listener - must not be null.public void removeListener(CommandListener listener)
listener - must not be null.protected List<CommandListener> getCommandListeners()
protected 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 connectionBuilder(Mono<SocketAddress> socketAddressSupplier, ConnectionBuilder connectionBuilder, ConnectionEvents connectionEvents, RedisURI redisURI)
socketAddressSupplier - address supplier for initial connect and re-connectconnectionBuilder - connection builder to configure the connectionconnectionEvents - connection events dispatcherredisURI - 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 close()
close in interface AutoCloseablepublic 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 © 2025 lettuce.io. All rights reserved.