Skip to content
Bluetape4k docs1.11

Clients and connections

Latest stable Based on Bluetape4k release 1.11.0

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(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.

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.

Continue with Commands and coroutines.