Clients and connections
Latest stable Based on Bluetape4k release 1.11.0
What a default client owns
Section titled “What a default client owns”LettuceClients.clientOf uses the process-wide DEFAULT_CLIENT_RESOURCES and applies keep-alive, TCP_NODELAY, and a connection timeout. Clients avoid creating separate event-loop pools, but the shared resource now has process lifetime.
val client = LettuceClients.clientOf("redis://redis:6379")val connection = LettuceClients.connect(client)check(connection.sync().ping() == "PONG")LettuceClients.shutdown(client)The same client and codec reuse an open cached connection. A closed connection is recreated under a per-client ReentrantLock. This cache is not a connection pool; concurrent callers share Lettuce’s thread-safe connection.
Shutdown order
Section titled “Shutdown order”shutdown(client) closes that client’s default and codec connections before shutting down the client. Parameterless shutdown() closes shared ClientResources, so call it only when every client is finished. Objects that call client.connect(codec) directly, including loaded maps, own and close those connections themselves.
Pipelines only issue commands
Section titled “Pipelines only issue commands”val futures = connection.withPipeline { commands -> (1..100).map { commands.set("item:$it", "v$it") }}futures.awaitAll()withPipeline disables auto-flush, flushes once after the block, and restores auto-flush in finally. Awaiting inside the block can wait for a result that has not been flushed.
Source and tests
Section titled “Source and tests”Continue with Commands and coroutines.