@Experimental public class StatefulRedisMultiDbConnectionImpl<C extends StatefulRedisConnection<K,V>,K,V> extends Object implements StatefulRedisMultiDbConnection<K,V>
| Modifier and Type | Field and Description |
|---|---|
protected RedisAsyncCommandsImpl<K,V> |
async |
protected RedisCodec<K,V> |
codec |
protected io.lettuce.core.failover.DatabaseConnectionFactory<C,K,V> |
connectionFactory |
protected Set<RedisConnectionStateListener> |
connectionStateListeners |
protected RedisDatabase<C> |
current |
protected Map<RedisURI,RedisDatabase<C>> |
databases |
protected HealthStatusManager |
healthStatusManager |
protected Supplier<JsonParser> |
parser |
protected Set<PushListener> |
pushListeners |
protected RedisReactiveCommandsImpl<K,V> |
reactive |
protected RedisCommands<K,V> |
sync |
| Constructor and Description |
|---|
StatefulRedisMultiDbConnectionImpl(Map<RedisURI,RedisDatabase<C>> connections,
ClientResources resources,
RedisCodec<K,V> codec,
Supplier<JsonParser> parser,
io.lettuce.core.failover.DatabaseConnectionFactory<C,K,V> connectionFactory,
HealthStatusManager healthStatusManager) |
| Modifier and Type | Method and Description |
|---|---|
void |
addDatabase(DatabaseConfig databaseConfig)
Add a new database to the multi-database connection.
|
void |
addDatabase(RedisURI redisURI,
float weight)
Add a new database to the multi-database connection.
|
void |
addListener(PushListener listener)
Add a new
listener to consume push messages. |
void |
addListener(RedisConnectionStateListener listener)
Add a listener for the
RedisConnectionStateListener. |
RedisAsyncCommands<K,V> |
async()
Returns the
RedisAsyncCommands API for the current connection. |
void |
close()
Close the connection.
|
CompletableFuture<Void> |
closeAsync()
Request to close the connection and return the
CompletableFuture that is notified about its progress. |
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.
|
protected void |
doByExclusiveLock(Runnable operation) |
protected void |
doBySharedLock(Runnable operation) |
void |
flushCommands()
Flush pending commands.
|
CircuitBreaker |
getCircuitBreaker(RedisURI endpoint)
Get the circuit breaker for a specific endpoint.
|
RedisCodec<K,V> |
getCodec() |
RedisURI |
getCurrentEndpoint()
Get the current database endpoint.
|
Iterable<RedisURI> |
getEndpoints()
Get all available database endpoints.
|
ClientOptions |
getOptions() |
ClientResources |
getResources() |
Duration |
getTimeout() |
boolean |
isHealthy(RedisURI endpoint)
Check if an endpoint is healthy (health status is HEALTHY and circuit breaker is CLOSED).
|
boolean |
isMulti() |
boolean |
isOpen() |
protected RedisAsyncCommandsImpl<K,V> |
newRedisAsyncCommandsImpl()
Create a new instance of
RedisAsyncCommandsImpl. |
protected RedisReactiveCommandsImpl<K,V> |
newRedisReactiveCommandsImpl()
Create a new instance of
RedisReactiveCommandsImpl. |
protected RedisCommands<K,V> |
newRedisSyncCommandsImpl()
Create a new instance of
RedisCommands. |
RedisReactiveCommands<K,V> |
reactive()
Returns the
RedisReactiveCommands API for the current connection. |
void |
removeDatabase(RedisURI redisURI)
Remove a database from the multi-database connection.
|
void |
removeListener(PushListener listener)
Remove an existing
listener. |
void |
removeListener(RedisConnectionStateListener listener)
Removes a listener.
|
void |
setAutoFlushCommands(boolean autoFlush)
Disable or enable auto-flush behavior.
|
void |
setTimeout(Duration timeout)
Set the default command timeout for this connection.
|
void |
switchToDatabase(RedisURI redisURI)
Switch to a different database.
|
RedisCommands<K,V> |
sync()
Returns the
RedisCommands API for the current connection. |
protected <T> T |
syncHandler(Object asyncApi,
Class<?>... interfaces) |
protected final Map<RedisURI,RedisDatabase<C extends StatefulRedisConnection<K,V>>> databases
protected final HealthStatusManager healthStatusManager
protected RedisDatabase<C extends StatefulRedisConnection<K,V>> current
protected final RedisCommands<K,V> sync
protected final RedisAsyncCommandsImpl<K,V> async
protected final RedisReactiveCommandsImpl<K,V> reactive
protected final RedisCodec<K,V> codec
protected final Supplier<JsonParser> parser
protected final Set<PushListener> pushListeners
protected final Set<RedisConnectionStateListener> connectionStateListeners
public StatefulRedisMultiDbConnectionImpl(Map<RedisURI,RedisDatabase<C>> connections, ClientResources resources, RedisCodec<K,V> codec, Supplier<JsonParser> parser, io.lettuce.core.failover.DatabaseConnectionFactory<C,K,V> connectionFactory, HealthStatusManager healthStatusManager)
public RedisAsyncCommands<K,V> async()
StatefulRedisConnectionRedisAsyncCommands API for the current connection. Does not create a new connection.async in interface StatefulRedisConnection<K,V>protected RedisCommands<K,V> newRedisSyncCommandsImpl()
RedisCommands. Can be overriden to extend.protected RedisAsyncCommandsImpl<K,V> newRedisAsyncCommandsImpl()
RedisAsyncCommandsImpl. Can be overriden to extend.public RedisReactiveCommands<K,V> reactive()
StatefulRedisConnectionRedisReactiveCommands API for the current connection. Does not create a new connection.reactive in interface StatefulRedisConnection<K,V>protected RedisReactiveCommandsImpl<K,V> newRedisReactiveCommandsImpl()
RedisReactiveCommandsImpl. Can be overriden to extend.public RedisCommands<K,V> sync()
StatefulRedisConnectionRedisCommands API for the current connection. Does not create a new connection.sync in interface StatefulRedisConnection<K,V>public void addListener(RedisConnectionStateListener listener)
StatefulConnectionRedisConnectionStateListener. The listener is notified every time a connect/disconnect/IO
exception happens. The listener is called on the event loop thread so code within the listener methods must not block.addListener in interface StatefulConnection<K,V>listener - must not be null.public void removeListener(RedisConnectionStateListener listener)
StatefulConnectionremoveListener in interface StatefulConnection<K,V>listener - must not be null.public void setTimeout(Duration timeout)
StatefulConnectionsetTimeout in interface StatefulConnection<K,V>timeout - Command timeout.public Duration getTimeout()
getTimeout in interface StatefulConnection<K,V>public <T> RedisCommand<K,V,T> dispatch(RedisCommand<K,V,T> command)
StatefulConnectiondispatch in interface StatefulConnection<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>commands - the Redis commands.public void close()
StatefulConnectionclose in interface StatefulConnection<K,V>close in interface AutoCloseablepublic CompletableFuture<Void> closeAsync()
StatefulConnectionCompletableFuture that is notified about its progress. The
connection will become not usable anymore as soon as this method was called.closeAsync in interface StatefulConnection<K,V>closeAsync in interface AsyncCloseableCompletableFuture that is notified once the operation completes, either because the operation was
successful or because of an error.public boolean isOpen()
isOpen in interface StatefulConnection<K,V>public ClientOptions getOptions()
getOptions in interface StatefulConnection<K,V>public ClientResources getResources()
getResources in interface StatefulConnection<K,V>public void setAutoFlushCommands(boolean autoFlush)
StatefulConnectiontrue. If autoFlushCommands is disabled, multiple commands can
be issued without writing them actually to the transport. Commands are buffered until a StatefulConnection.flushCommands() is
issued. After calling StatefulConnection.flushCommands() commands are sent to the transport and executed by Redis.setAutoFlushCommands in interface StatefulConnection<K,V>autoFlush - state of autoFlush.public void flushCommands()
StatefulConnectionflushCommands in interface StatefulConnection<K,V>public boolean isMulti()
isMulti in interface StatefulRedisConnection<K,V>public void addListener(PushListener listener)
StatefulRedisConnectionlistener to consume push messages.addListener in interface StatefulRedisConnection<K,V>listener - the listener, must not be null.public void removeListener(PushListener listener)
StatefulRedisConnectionlistener.removeListener in interface StatefulRedisConnection<K,V>listener - the listener, must not be null.public RedisCodec<K,V> getCodec()
getCodec in interface StatefulConnection<K,V>RedisCodec used by this connection.public RedisURI getCurrentEndpoint()
BaseRedisMultiDbConnectiongetCurrentEndpoint in interface BaseRedisMultiDbConnectionpublic Iterable<RedisURI> getEndpoints()
BaseRedisMultiDbConnectiongetEndpoints in interface BaseRedisMultiDbConnectionpublic void switchToDatabase(RedisURI redisURI)
BaseRedisMultiDbConnectionswitchToDatabase in interface BaseRedisMultiDbConnectionredisURI - the Redis URI of the database to switch to, must not be nullprotected void doBySharedLock(Runnable operation)
protected void doByExclusiveLock(Runnable operation)
public CircuitBreaker getCircuitBreaker(RedisURI endpoint)
BaseRedisMultiDbConnectiongetCircuitBreaker in interface BaseRedisMultiDbConnectionendpoint - the Redis endpoint URIpublic boolean isHealthy(RedisURI endpoint)
BaseRedisMultiDbConnectionisHealthy in interface BaseRedisMultiDbConnectionendpoint - the Redis endpoint URIpublic void addDatabase(RedisURI redisURI, float weight)
BaseRedisMultiDbConnectionaddDatabase in interface BaseRedisMultiDbConnectionredisURI - the Redis URI for the new database, must not be nullweight - the weight for load balancing, must be greater than 0public void addDatabase(DatabaseConfig databaseConfig)
BaseRedisMultiDbConnectionaddDatabase in interface BaseRedisMultiDbConnectiondatabaseConfig - the database configuration, must not be nullpublic void removeDatabase(RedisURI redisURI)
BaseRedisMultiDbConnectionremoveDatabase in interface BaseRedisMultiDbConnectionredisURI - the Redis URI of the database to remove, must not be nullCopyright © 2025 lettuce.io. All rights reserved.