Skip to main content

RateLimitStore

@forge/monorepo


@forge/monorepo / backend/src / RateLimitStore

Interface: RateLimitStore

Defined in: backend/src/usage/rate-limit.ts:84

The counter, as a port.

consume must be atomic and must set the expiry in the same operation. An INCR followed by a separate EXPIRE is the obvious implementation and it is wrong: a process dying between the two leaves a key with no TTL, and that tenant is refused for ever. The Redis adapter uses one script.

Methods

consume()

consume(input): Promise<number>

Defined in: backend/src/usage/rate-limit.ts:85

Parameters

input
tenantId

TenantId

windowSeconds

number

windowStartMs

number

The truncated window start, in epoch milliseconds — the key's identity.

Returns

Promise<number>