Limiter v3.1.0 Release: Dry Run Mode, limit:exceeded Event, and Safer Redis clear()
· Developer impact : medium
The @adonisjs/limiter package version 3.1.0 introduces a new dry run mode for HTTP limiters that counts requests without rejecting them, emitting a 'limit:exceeded' event with a dryRun flag. The package now emits a 'limit:exceeded' event whenever a request is rejected, useful for logging or metrics. Additionally, the Redis store's clear() method no longer flushes the entire database but only deletes keys under the configured keyPrefix, preventing unintended data loss. Calling clear() without a keyPrefix now throws an error.
Developers can now monitor rate limit exceedances via the new 'limit:exceeded' event to log or collect metrics without delaying requests. The dry run mode allows testing limits on live traffic without enforcement, facilitating safer rollout of rate limits. The change to clear() behavior prevents accidental flushing of unrelated Redis data, which may require review of existing usage if clear() was called on a Redis store without a keyPrefix, as this now throws an error.
- Update code to listen for the 'limit:exceeded' event if logging or metrics are desired.
- Use .dryRun() on HTTP limiters to test rate limits without rejecting requests.
- Review usage of Redis store's clear() method; ensure keyPrefix is set or avoid calling clear() to prevent errors.
- Test rate limiting behavior with the new dry run mode and event emissions to confirm expected operation.
Original sources
AI-generated analysis based on the linked sources. Check the original documentation before changing your application.