Module lettuce.core

Class AsyncConnectionPoolSupport

java.lang.Object
io.lettuce.core.support.AsyncConnectionPoolSupport

public abstract class AsyncConnectionPoolSupport
extends Object
Asynchronous connection pool support for BoundedAsyncPool. Connection pool creation requires a Supplier that connects asynchronously to Redis. The pool can allocate either wrapped or direct connections.

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

Transactions and command batching affect connection state. Blocking commands won't propagate queued commands to Redis until the blocking command is completed.

Example


 // 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();
 
Since:
5.1
Author:
Mark Paluch