View Source Hammer.EredisCluster.FixWindow (hammer_backend_eredis_cluster v2.0.0)
The fixed-window algorithm on a Redis cluster.
Time is divided into fixed windows of scale milliseconds; each window keeps
an independent counter. A hit increments the current window's counter and is
allowed while the counter is within the limit; once over, the deny tuple
carries the time (ms) until the window rolls over.
Same shape as Hammer.Redis.FixWindow, with two cluster-specific twists:
- commands are routed through eredis_cluster with the window key as the
routing key, and Redis keys embed a
{key}hash tag so every window of a key lands on the same cluster slot; - the expiry is set with an unconditional
PEXPIREATof the (constant) window end instead ofEXPIREAT ... NX— idempotent across hits and does not require Redis >= 7 for theNXflag.
Summary
Functions
When the current fixed window ends, as a unix timestamp in milliseconds.
Functions
@spec expires_at(String.t(), pos_integer()) :: pos_integer()
When the current fixed window ends, as a unix timestamp in milliseconds.
Purely time-derived for the fixed-window algorithm (windows are aligned to the epoch), so no Redis round-trip is made; the key is irrelevant.
@spec get(atom(), String.t(), String.t(), pos_integer()) :: non_neg_integer()
@spec hit(atom(), String.t(), String.t(), pos_integer(), pos_integer(), pos_integer()) :: {:allow, pos_integer()} | {:deny, pos_integer()}
@spec inc(atom(), String.t(), String.t(), pos_integer(), pos_integer()) :: pos_integer()
@spec set(atom(), String.t(), String.t(), pos_integer(), non_neg_integer()) :: non_neg_integer()