pyrate_limiter.buckets.redis_state module

Redis-backed store for constant-state algorithms.

class pyrate_limiter.buckets.redis_state.RedisStateStore(redis, key, ttl_ms=None)

Bases: StateStore

One Redis hash per key, holding a few floats however much traffic passes.

This is where the constant-state algorithms pay off: a sorted-set log grows with every consumed unit and must be trimmed, while this stays the same size and expires on its own.

The transition runs as Lua so the read-modify-write is atomic across clients. Works with either a sync or an async redis client.

check(algorithm, rates, now, weight)

Apply algorithm.step to the stored state, atomically.

default_clock = <pyrate_limiter.clocks.WallClock object>

State is shared between machines, where a monotonic clock is meaningless.

is_async = None

Unknown until the client is seen; the Leaker probes. leak() on StateBucket is a sync no-op either way.

read(algorithm, rates)

Current state. For reporting only - never the basis of a decision.

reset()

Forget everything, as though the key had never been used.

Return type:

None | Awaitable[None]