Package com.dehnes.kotlinredis.pool
Class RedisConnectionPool
-
- All Implemented Interfaces:
-
java.io.Closeable,java.lang.AutoCloseable
public final class RedisConnectionPool implements Closeable
-
-
Field Summary
Fields Modifier and Type Field Description private final IntegerdatabaseIndex
-
Constructor Summary
Constructors Constructor Description RedisConnectionPool(InetSocketAddress addr, Long connectTimeoutMs, Integer databaseIndex, Integer readTimeoutMs, Integer maxConnections, Duration keepAlive, RedisTls tls)
-
Method Summary
Modifier and Type Method Description final IntegergetDatabaseIndex()final <T extends Any> TwithConnection(Duration timeout, Function1<RedisConnection, T> fn)Acquires a connection from the pool and run the provides lamba with this connection. Unitclose()Closes all connections of the pool. -
-
Method Detail
-
getDatabaseIndex
final Integer getDatabaseIndex()
-
withConnection
final <T extends Any> T withConnection(Duration timeout, Function1<RedisConnection, T> fn)
Acquires a connection from the pool and run the provides lamba with this connection.
If any exception is thrown, regardless which kind, then the connection is considered unrecoverable, is closed and not returned to the pool. It is relative cheap to create new connections to Redis and this is a much safer way then trying to figure out whether the exception was caused by from the provided lamba or from the Redis client code somehow.
- Parameters:
timeout- max time to wait for an available connection.- Returns:
the value returned by the lamba
-
-
-
-