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 PEXPIREAT of the (constant) window end instead of EXPIREAT ... NX — idempotent across hits and does not require Redis >= 7 for the NX flag.

Summary

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.

Link to this function

get(cluster, prefix, key, scale)

View Source
@spec get(atom(), String.t(), String.t(), pos_integer()) :: non_neg_integer()
Link to this function

hit(cluster, prefix, key, scale, limit, increment)

View Source
@spec hit(atom(), String.t(), String.t(), pos_integer(), pos_integer(), pos_integer()) ::
  {:allow, pos_integer()} | {:deny, pos_integer()}
Link to this function

inc(cluster, prefix, key, scale, increment)

View Source
@spec inc(atom(), String.t(), String.t(), pos_integer(), pos_integer()) ::
  pos_integer()
Link to this function

set(cluster, prefix, key, scale, count)

View Source