express-quota-limiter ships with two built-in storage drivers. RedisDriver is designed for production use — it stores quota state in Redis using atomic pipeline operations so there are no race conditions. MemoryDriver keeps state in process memory and requires no external dependencies, making it ideal for local development and testing.
RedisDriver
RedisDriver uses a Redis MULTI/EXEC pipeline to atomically initialize a key (only if it does not already exist) and decrement it in a single round-trip. It works with both ioredis and node-redis v4.
Constructor
An active Redis client instance. Accepts either an
ioredis client or a node-redis v4 client. The driver detects which client you have passed and uses the correct pipeline API automatically.The TTL in seconds applied when a quota key is first created. The default is
2592000 (30 days), which matches a typical monthly quota window. The TTL is only set on initial key creation — it is not renewed on every request.Usage examples
Methods
decrement(key, limit?, weight?)
Atomically initializes the key at limit (if missing) and decrements by weight. Returns a QuotaResult with { success, remaining }.
increment(key, weight)
Increments the stored value for key by weight. Use this to refund quota — for example, when a background job fails after the middleware has already decremented.
MemoryDriver
MemoryDriver stores quota entries in a Map inside the current Node.js process. It has no external dependencies and no setup required, which makes it the recommended driver for unit and integration tests.
Constructor
The TTL in seconds for each quota window. When a key expires or does not yet exist, it is re-initialized at the configured
limit on the next request. The default is 2592000 (30 days).Usage example
Methods
decrement(key, limit?, weight?)
Initializes the key at limit (if missing or expired) and decrements by weight. Returns a QuotaResult with { success, remaining }.
increment(key, weight)
Increments the stored value for key by weight. Has no effect if the key does not exist.
clear()
Removes all entries from the in-memory store. Call this between tests to ensure each test starts with a clean state.
inspect(key)
Returns the raw store entry for the given key, or undefined if the key does not exist. The returned object has the shape { remaining: number, expiresAt: number } where expiresAt is a Unix millisecond timestamp.
Custom drivers
You can implement your own driver for any storage backend by satisfying theQuotaStorage interface:
QuotaStorage interface definition.