Skip to content
Leader docs0.4

Redis Lettuce backend

Latest stable Based on Leader release 0.4.0

Library module

Implements single, fixed-slot group, and strategic election with Lettuce connections, token-owned Redis keys, Lua compare-and-delete/extend, and blocking/coroutine APIs.

Choose it when Redis is already operated and the application prefers Lettuce’s connection model and explicit scripting.

Artifact: io.github.bluetape4k.leader:bluetape4k-leader-redis-lettuce

dependencies {
implementation(platform("io.github.bluetape4k:bluetape4k-dependencies:<version>"))
implementation("io.github.bluetape4k.leader:bluetape4k-leader-redis-lettuce")
}

A unique token owns a TTL key. Lua scripts make release and extension conditional. Strategic election stores candidate metadata and applies Core strategies.

val elector = LettuceLeaderElector(connection)
elector.runIfLeader("daily-report") { generateReport() }

Use the connection extension/factory, blocking/suspend single/group electors, and strategic electors. The connection is caller-owned.

Use a dedicated key prefix, keep Redis client and connection lifecycle explicit, make actions idempotent, and plan behavior during failover.

Spring can build factories from Lettuce resources. strategic-election and rate-limiter show candidate and group patterns.

Configure wait/lease/minimum lease, auto-extension, key prefix, group size, retry, client timeouts, topology refresh, and Redis durability policy.

Contention returns null. Timeout, MOVED/topology, script, authentication, and extension failures propagate. Expired ownership can overlap an old paused action.

Monitor command latency, reconnects, topology changes, script failures, keyspace/TTL, extension failure, skip rate, and Redis memory pressure.

Use Redis integration tests for two connections, token-safe release, expiry, group slots, strategic registry, failover handling, and suspend cancellation.

Run strategic-election for candidate scoring and rate-limiter for group slots; compare Lettuce with Redisson’s higher-level client model.

Redis availability and failover semantics are on the job path. A Redis token is not fencing for an external database.

These diagrams are loaded directly from README assets published with the 0.4.0 release and pinned to its immutable commit. They describe this manual’s released structure and runtime flows, not later Snapshot changes. Select a preview to open the SVG at the same release commit.

Lettuce Redis leader contract map

Release README: leader-redis-lettuce/README.md

Lettuce slot-token acquire release and crash recovery flow

Section titled “Lettuce slot-token acquire release and crash recovery flow”

Lettuce slot-token acquire release and crash recovery flow

Release README: leader-redis-lettuce/README.md

Lettuce minLeaseTime backend TTL delegation flow

Section titled “Lettuce minLeaseTime backend TTL delegation flow”

Lettuce minLeaseTime backend TTL delegation flow

Release README: leader-redis-lettuce/README.md

Elector · Lua support · Stable guide