Gathering detailed insights and metrics for sliding-window-rate-limiter
Gathering detailed insights and metrics for sliding-window-rate-limiter
Gathering detailed insights and metrics for sliding-window-rate-limiter
Gathering detailed insights and metrics for sliding-window-rate-limiter
redis-sliding-rate-limiter
Flexible and performant rate limiter based on sliding window algorithm with arbitrary precision
pauls-sliding-window-rate-limiter
Efficiently rate limit calls using a sliding window algorithm.
rate-limiter-sliding
A generic rate limiter that can be used to limit requests, or anything just by using key, can protect from brute-force and DDoS attacks
rate-limiter-algorithms
Library that provides different algorithms to perform rate limiting
npm install sliding-window-rate-limiter
Typescript
Module System
Min. Node Version
Node Version
NPM Version
72.3
Supply Chain
99.4
Quality
77.3
Maintenance
100
Vulnerability
99.3
License
TypeScript (91.2%)
Lua (6.25%)
JavaScript (2.55%)
Total Downloads
61,354
Last Day
58
Last Week
393
Last Month
1,410
Last Year
21,118
13 Stars
210 Commits
4 Forks
2 Watching
11 Branches
4 Contributors
Minified
Minified + Gzipped
Latest Version
6.0.1
Package Id
sliding-window-rate-limiter@6.0.1
Unpacked Size
41.06 kB
Size
8.91 kB
File Count
25
NPM Version
10.8.1
Node Version
22.3.0
Publised On
25 Jun 2024
Cumulative downloads
Total Downloads
Last day
114.8%
58
Compared to previous day
Last week
37.4%
393
Compared to previous week
Last month
6.4%
1,410
Compared to previous month
Last year
26.4%
21,118
Compared to previous year
Sliding window rate limiter with Redis >= 3.2 backend or in-memory backend.
This module requires ES6 with Node >= 16.
Redis >= 3.2.0 is required for the Redis backend.
1npm install sliding-window-rate-limiter
Additionally for Typescript:
1npm install -D @types/node @types/ioredis
1const {SlidingWindowRateLimiter} = require("sliding-window-rate-limiter")
Typescript:
1import SlidingWindowRateLimiter from "sliding-window-rate-limiter" 2// or 3import {SlidingWindowRateLimiter} from "sliding-window-rate-limiter"
1const limiter = SlidingWindowRateLimiter.createLimiter(options)
Options:
interval
is a number of milliseconds in a sliding windowredis
is an instance of ioredis
or URL string to Redis server (only for Redis backend)operationTimeout
is the time in milliseconds after Redis operation is canceled
(for Redis and SafeRedis backends, optional)safe
: true
(only for SafeRedis backend)
reuseRedisAfter
is the time (milliseconds) to reconnect to the Redis server
after connection failure (only for SafeRedis backend, default value: 2000
milliseconds)If redis
parameter is a string then a new ioredis
object is created with
retryStrategy
set to 1 second and maxRetriesPerRequest
set to 1.
Example:
1const limiter = SlidingWindowRateLimiter.createLimiter({
2 interval: 60000,
3})
or
1const limiter = SlidingWindowRateLimiter.createLimiter({
2 interval: 60000,
3 redis: new Redis({
4 host: "redis-server",
5 retryStrategy: _times => 1000,
6 maxRetriesPerRequest: 1,
7 }),
8 safe: true,
9})
1const result = await limiter.check(key, limit) 2const {usage, reset} = result
Checks current usage for key
. If usage
is equal to or above limit
,
additionally sets reset
time in milliseconds.
1const result = await limiter.reserve(key, limit) 2const {token, usage, reset} = result
Makes a reservation and returns token
with a reservation. If usage
is
equal to or above limit
, additionally sets reset
time in milliseconds.
Throws an error if has occurred.
1const result = await limiter.cancel(key, token) 2const {canceled} = result
Cancels a reservation for token
and returns the number of `canceled``
tokens. It is a zero if no token previously was reserved or it was expired.
1limiter.destroy()
Frees resources used by limiter (timers and Redis connection if created by limiter itself).
If reserve
or usage
methods return an error:
1ERR Error running script (call to f_8ff6a0f745b738fe1d9fa74079c4c13d032e9947): @user_script:1: user_script:1: attempt to call field \'replicate_commands\' (a nil value)
then check if Redis has the proper version (>= 3.2.0).
This backend holds all data in memory.
This backend requires Redis 3.2 to work. The main advantage is that the state of the limiter can be shared between many clients.
There is an extended version of the limiter, which behaves gracefully when
the Redis server is unavailable for any reason. In case of Redis connection
failure, SafeRedis backend will always return a positive response object and
will try to use again the Redis server after reuseRedisAfter
.
Copyright (c) 2017-2024 Piotr Roszatycki piotr.roszatycki@gmail.com
Based on Lua script from https://github.com/3hedgehogs/inredis-ratelimiter
Copyright (c) 2017 Serguei Poliakov serguei.poliakov@gmail.com
Inspired by ClassDojo blog note
https://engineering.classdojo.com/blog/2015/02/06/rolling-rate-limiter/ and
rolling-rate-limiter
module.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
packaging workflow detected
Details
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/9 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More