public abstract class AsyncConnectionPoolSupport extends Object
BoundedAsyncPool. Connection pool creation requires a Supplier that
connects asynchronously to Redis. The pool can allocate either wrapped or direct connections.
StatefulConnection.close()/
StatefulConnection.closeAsync().AsyncPool.release(Object)
Lettuce connections are designed to be thread-safe so one connection can be shared amongst multiple threads and Lettuce
connections auto-reconnect by default. Connection pooling with Lettuce can be
required when you're invoking Redis operations in multiple threads and you use
BLPOP.BLPOP.command batching.
// application initialization
RedisClusterClient clusterClient = RedisClusterClient.create(RedisURI.create(host, port));
AsyncPool<StatefulRedisConnection<String, String>> pool = AsyncConnectionPoolSupport
.createBoundedObjectPool(() -> clusterClient.connectAsync(), BoundedPoolConfig.create());
// executing work
CompletableFuture<String> pingResponse = pool.acquire().thenCompose(c -> {
return c.async().ping().whenComplete((s, throwable) -> pool.release(c));
});
// terminating
CompletableFuture<Void> poolClose = pool.closeAsync();
// after poolClose completes:
CompletableFuture<Void> closeFuture = clusterClient.shutdown();
| Modifier and Type | Method and Description |
|---|---|
static <T extends StatefulConnection<?,?>> |
createBoundedObjectPool(Supplier<CompletionStage<T>> connectionSupplier,
BoundedPoolConfig config)
Create and initialize asynchronously a new
BoundedAsyncPool using the Supplier. |
static <T extends StatefulConnection<?,?>> |
createBoundedObjectPool(Supplier<CompletionStage<T>> connectionSupplier,
BoundedPoolConfig config,
boolean wrapConnections)
Create and initialize asynchronously a new
BoundedAsyncPool using the Supplier. |
static <T extends StatefulConnection<?,?>> |
createBoundedObjectPoolAsync(Supplier<CompletionStage<T>> connectionSupplier,
BoundedPoolConfig config)
Create and initialize asynchronously a new
BoundedAsyncPool using the Supplier. |
static <T extends StatefulConnection<?,?>> |
createBoundedObjectPoolAsync(Supplier<CompletionStage<T>> connectionSupplier,
BoundedPoolConfig config,
boolean wrapConnections)
Create and initialize asynchronously a new
BoundedAsyncPool using the Supplier. |
protected static <T extends StatefulConnection<?,?>> |
doCreatePool(Supplier<CompletionStage<T>> connectionSupplier,
BoundedPoolConfig config,
boolean wrapConnections) |
public static <T extends StatefulConnection<?,?>> BoundedAsyncPool<T> createBoundedObjectPool(Supplier<CompletionStage<T>> connectionSupplier, BoundedPoolConfig config)
BoundedAsyncPool using the Supplier. Allocated instances are
wrapped and must not be returned with AsyncPool.release(Object).
Please note that pool initialization (creation of idle connections) cannot be awaited using this method. Use for these
purposes createBoundedObjectPoolAsync(Supplier, BoundedPoolConfig) instead. This method will be changed with
Lettuce 6 to a blocking method to await pool initialization.
T - connection type.connectionSupplier - must not be null.config - must not be null.public static <T extends StatefulConnection<?,?>> BoundedAsyncPool<T> createBoundedObjectPool(Supplier<CompletionStage<T>> connectionSupplier, BoundedPoolConfig config, boolean wrapConnections)
BoundedAsyncPool using the Supplier.
Please note that pool initialization (creation of idle connections) cannot be awaited using this method. Use for these
purposes createBoundedObjectPoolAsync(Supplier, BoundedPoolConfig, boolean) instead. This method will be changed
with Lettuce 6 to a blocking method to await pool initialization.
T - connection type.connectionSupplier - must not be null.config - must not be null.wrapConnections - false to return direct connections that need to be returned to the pool using
AsyncPool.release(Object). true to return wrapped connection that are returned to the pool when
invoking StatefulConnection.close()/StatefulConnection.closeAsync().public static <T extends StatefulConnection<?,?>> CompletionStage<BoundedAsyncPool<T>> createBoundedObjectPoolAsync(Supplier<CompletionStage<T>> connectionSupplier, BoundedPoolConfig config)
BoundedAsyncPool using the Supplier. Allocated instances are
wrapped and must not be returned with AsyncPool.release(Object).T - connection type.connectionSupplier - must not be null.config - must not be null.CompletionStage emitting the connection pool upon completion.public static <T extends StatefulConnection<?,?>> CompletionStage<BoundedAsyncPool<T>> createBoundedObjectPoolAsync(Supplier<CompletionStage<T>> connectionSupplier, BoundedPoolConfig config, boolean wrapConnections)
BoundedAsyncPool using the Supplier.T - connection type.connectionSupplier - must not be null.config - must not be null.wrapConnections - false to return direct connections that need to be returned to the pool using
AsyncPool.release(Object). true to return wrapped connection that are returned to the pool when
invoking StatefulConnection.close()/StatefulConnection.closeAsync().CompletionStage emitting the connection pool upon completion.protected static <T extends StatefulConnection<?,?>> BoundedAsyncPool<T> doCreatePool(Supplier<CompletionStage<T>> connectionSupplier, BoundedPoolConfig config, boolean wrapConnections)
Copyright © 2021 lettuce.io. All rights reserved.