Strategy to acquire a machine ID lease from Redis, coordinating uniqueness across nodes through a single Redis hash.
Each machine ID (0..511) is a field in the hash; a node acquires the lowest free ID and
holds it by keeping that field's value (a random token) alive with a TTL, renewing it
periodically.
Requires Redis 8+ or Valkey 9+ for HSETEX's conditional (FNX/FXX) and per-field TTL support.
Configure the strategy when starting NoNoncense.MachineId, after your Redix instance or pool:
children = [
...
MyApp.Redix,
{NoNoncense.MachineId,
strategy: NoNoncense.MachineId.Strategy.RedisLease,
strategy_opts: [with_connection: MyApp.Redix],
instances: [[base_key: System.fetch_env!("BASE_KEY")]]}
]Options
:with_connection(required) supports two forms:- Pass the simple connection name or pid directly:
with_connection: MyApp.Redix - To support connection pools, pass a function that calls its argument function with a connection:
with_connection: fn fun -> :poolboy.transaction(MyApp.RedixPool, fun) end
- Pass the simple connection name or pid directly:
:key- the Redis hash key to store leases under (default"no_noncense_leases")
Summary
Types
@type opt() :: {:with_connection, with_connection()} | {:key, binary()}
@type with_connection() :: ((Redix.connection() -> any()) -> any()) | Redix.connection()