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)
Creates a new
BoundedAsyncPool using the Supplier. |
static <T extends StatefulConnection<?,?>> |
createBoundedObjectPool(Supplier<CompletionStage<T>> connectionSupplier,
BoundedPoolConfig config,
boolean wrapConnections)
Creates a new
BoundedAsyncPool using the Supplier. |
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).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.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().Copyright © 2019 lettuce.io. All rights reserved.