Class ConnectionPoolSupport


  • public abstract class ConnectionPoolSupport
    extends Object
    Connection pool support for GenericObjectPool and SoftReferenceObjectPool. Connection pool creation requires a Supplier that creates Redis connections. 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));
     GenericObjectPool<StatefulRedisClusterConnection<String, String>> pool = ConnectionPoolSupport
             .createGenericObjectPool(() -> clusterClient.connect(), new GenericObjectPoolConfig());
    
     // executing work
     try (StatefulRedisClusterConnection<String, String> connection = pool.borrowObject()) {
         // perform some work
     }
    
     // terminating
     pool.close();
     clusterClient.shutdown();
     
    Since:
    4.3
    Author:
    Mark Paluch