Skip to content

Commit

Permalink
docs: improve store-related docs (#437)
Browse files Browse the repository at this point in the history
* mention prefix and link to appropriate setting in known stores from ERR_ERL_DOUBLE_COUNT docs
* mention stores in readme example

---------

Co-authored-by: Vedant K <gamemaker0042@gmail.com>
  • Loading branch information
nfriedly and gamemaker1 committed Feb 20, 2024
1 parent 31fc799 commit c252ae3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions docs/reference/error-codes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,19 @@ Set `validate: {positiveHits: false}` in the options to disable the check.
This indicates that the hit count for a given IP or key was incremented more
than once for a single request. It could happen if the same instance of
express-rate-limit is called more than once, or if multiple instances are called
that use the same Store.

If only a single rate limit is desired, find and remove the extra rateLimit
call(s).

If multiple rate limits are desired, consider setting a custom `keyGenerator`
for each to prevent double-counting.
that use the same [Store](/reference/stores).

- If only a single rate limit is desired, find and remove the extra rateLimit
call(s).

- If multiple rate limits are desired, consider one of the following options:
- Set a custom `prefix` in the configuration for each store instance.
([Redis](https://www.npmjs.com/package/rate-limit-redis#prefix),
[Memcached](https://www.npmjs.com/package/rate-limit-memcached#prefix),
[PostgreSQL](https://www.npmjs.com/package/@acpr/rate-limit-postgresql#constructor),
[Cluster](https://www.npmjs.com/package/@express-rate-limit/cluster-memory-store#prefix))
- Set a custom [`keyGenerator`](/reference/configuration#keygenerator) in the
configuration for each express-rate-limit instance.

In rare circumstances this error can be a false positive. This would include
situations where multiple rate limiters are configured to use the same key but
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const limiter = rateLimit({
limit: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes).
standardHeaders: 'draft-7', // draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header
legacyHeaders: false, // Disable the `X-RateLimit-*` headers.
// store: ... , // Redis, Memcached, etc. See the `Data Stores` section below.
// store: ... , // Redis, Memcached, etc. See below.
})

// Apply the rate limiting middleware to all requests.
Expand Down

0 comments on commit c252ae3

Please sign in to comment.