Skip to main content

Module counter

Module counter 

Source
Expand description

Redis-backed fixed-window counter (policy: redis for limit-count and the workflow limit-count action).

Increment-and-check runs as one server-side Lua script so concurrent gateway instances count atomically. Window boundaries are wall-clock aligned (now / window), so every instance agrees on them — unlike the local store’s per-process Instant windows. Backend errors bump gateway_counter_store_errors_total{store} and surface as CounterError; the calling plugin decides fail-open vs reject.

Structs§

RedisCounterStore

Constants§

FIXED_WINDOW_SCRIPT 🔒
INCR + first-increment PEXPIRE + PTTL, atomically.

Functions§

window_key 🔒
The key for one fixed window of one counter.
window_slot 🔒
Wall-clock window slot: the window index (key component shared by all instances) and the milliseconds from now_ms to the window’s end (the PEXPIRE argument). Pure, so the boundary math is unit-testable.