-
-
Notifications
You must be signed in to change notification settings - Fork 163
Memory
Roman edited this page Oct 30, 2021
·
11 revisions
It manages limits in current process memory.
It expires limited keys by setTimeout
. Works in browser as well.
Note: the maximum duration
, blockDuration
and rateLimiter.block(key, secDuration)
for memory limiter is 2147483 seconds or about 24 days because of setTimeout
limitation.
const { RateLimiterMemory } = require('rate-limiter-flexible');
const rateLimiter = new RateLimiterMemory({
points: 6,
duration: 1,
});
rateLimiter.consume(key, 2) // Consume 2 points
.then((rateLimiterRes) => {
// Allowed
})
.catch((rej) => {
// Blocked
});
Get started
Middlewares and plugins
Migration from other packages
Limiters:
- Redis
- Memory
- DynamoDB
- Prisma
- MongoDB (with sharding support)
- PostgreSQL
- MySQL
- BurstyRateLimiter
- Cluster
- PM2 Cluster
- Memcached
- RateLimiterUnion
- RateLimiterQueue
Wrappers:
- RLWrapperBlackAndWhite Black and White lists
Knowledge base:
- Block Strategy in memory
- Insurance Strategy
- Comparative benchmarks
- Smooth out traffic peaks
-
Usage example
- Minimal protection against password brute-force
- Login endpoint protection
- Websocket connection prevent flooding
- Dynamic block duration
- Different limits for authorized users
- Different limits for different parts of application
- Block Strategy in memory
- Insurance Strategy
- Third-party API, crawler, bot rate limiting