createQuotaLimiter call requires a storage option that satisfies the QuotaStorage interface. The library ships with two built-in drivers—RedisDriver for production and MemoryDriver for development and tests—and the interface is simple enough to implement for any backend.
The QuotaStorage interface
Both built-in drivers implement this interface:
decrement is called on every incoming request. It receives the quota key, the resolved limit, and the request weight, and returns { success, remaining }. increment is used for manual quota adjustments — see the custom driver guide for details.
RedisDriver
RedisDriver is the recommended driver for production. It works with both ioredis and node-redis v4 — you inject whichever client you already use.
Atomic operations
The driver uses a RedisMULTI/EXEC pipeline to perform two operations atomically on every request:
SET key limit NX EX ttl— initialises the key to the limit value only if it does not already exist.DECRBY key weight— subtracts the request weight from the counter.
Instantiation
RedisDriverOptions
The TTL is set only on key creation. If the key already exists, its expiry is not extended.
MemoryDriver
MemoryDriver stores quota counters in a Map inside the running process. It has no external dependencies and needs no infrastructure to run.
Instantiation
Test helpers
MemoryDriver exposes two additional methods useful in tests:
driver.clear()— wipes all quota data. Call this inafterEachto reset state between tests.driver.inspect(key)— returns the raw{ remaining, expiresAt }entry for a key, orundefined.
MemoryDriverOptions
Custom driver
ImplementQuotaStorage to use any backend — SQL, DynamoDB, Firestore, or anything else: