Stone.js API
    Preparing search index...

    Shared fixed-window limiter, over Redis.

    The one to use wherever the application runs as more than one process, which is the case that warrants a limiter at all: per-process counters let every instance grant the full budget again.

    One round trip per request, and no read. The window index is part of the key, so a new window is a new key that starts at zero, and the counter's own expiry cleans up after it: there is nothing to sweep and nothing to read-modify-write. INCR and the expiry travel in one pipeline, because an INCR whose PEXPIRE never arrived is a counter that never resets, and one lost round trip would lock a caller out of that key forever.

    ioredis is imported lazily and is an optional peer, so this module carries no Redis weight until a Redis limiter is actually configured.

    Implements

    Index
    • Count one hit and say whether it may proceed.

      Parameters

      • key: string

        What the budget belongs to.

      • limit: number

        How many hits the window allows.

      • windowMs: number

        How long the window lasts.

      Returns Promise<RateLimitHit>

      The verdict.