RedisSharedStateStore

class RedisSharedStateStore(commands: RedisAsyncCommands<String, String>, keyPrefix: String = "arrow-resilience:", ttl: Duration? = null) : SharedStateStore

Redis-backed SharedStateStore (via Lettuce) for coordinating resilience state across instances, e.g. with DistributedRateLimiter and DistributedCircuitBreaker. compareAndSet is atomic through a Lua script.

Lettuce is a compileOnly dependency: add io.lettuce:lettuce-core yourself.

val store = RedisSharedStateStore(client.connect().async(), keyPrefix = "myapp:", ttl = 1.hours)

Parameters

commands

Lettuce async commands

keyPrefix

prefix applied to every key

ttl

optional expiry refreshed on each write

Constructors

Link copied to clipboard
constructor(commands: RedisAsyncCommands<String, String>, keyPrefix: String = "arrow-resilience:", ttl: Duration? = null)

Functions

Link copied to clipboard
open suspend override fun compareAndSet(key: String, expected: String?, new: String): Boolean

Atomically sets key to new only if its current value equals expected (null meaning "absent"). Returns whether the update happened — the building block for distributed counters/state machines.

Link copied to clipboard
open suspend override fun get(key: String): String?

Reads the current value for key, or null if absent.

Link copied to clipboard
open suspend override fun remove(key: String)

Removes key, if present.

Link copied to clipboard
open suspend override fun set(key: String, value: String)

Unconditionally sets key to value.