Registry / devops / redis-rate-limiter

redis-rate-limiter

JSON →
library1.2.0jsnpmunverified

Rate-limit any operation with Redis, using a fixed-window algorithm. Current stable version is 1.2.0. The package is lightweight and focuses on performance (>10,000 checks/sec on local Redis) and race-condition safety. It provides a simple API for creating rate limiters with shorthands like '100/minute' and includes built-in HTTP middleware for Express/Restify. Unlike rolling-window implementations like ratelimiter, this uses fixed windows which can allow traffic bursts at window edges. The package has low maintenance activity and limited documentation, but works reliably for basic use cases.

npm install redis-rate-limiter
INSTALL
IMPORT
SIG · REDIS-RATE-LIMITER
R
redis-rate-limiter
devopsjavascriptv1.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

rateLimiter
const rateLimiter = require('redis-rate-limiter');
import rateLimiter from 'redis-rate-limiter';
The package does not ship TypeScript types and is CommonJS only. Use require().
create
const limit = rateLimiter.create({ redis: client, key: 'ip', rate: '100/minute' });
const limit = new rateLimiter({ redis: client, key: 'ip', rate: '100/minute' });
create() is a factory function, not a constructor. Do not use 'new'.
middleware
const middleware = rateLimiter.middleware({ redis: client, key: 'ip', rate: '100/minute' });
app.use(rateLimiter({ redis: client, key: 'ip', rate: '100/minute' }));
middleware() returns a function that can be used with app.use(). Do not pass options directly to middleware.

Creates a Redis client and a rate limiter with a limit of 100 requests per minute based on IP. Simulates periodic requests and logs the result.

const redis = require('redis'); const client = redis.createClient({ enable_offline_queue: false }); const rateLimiter = require('redis-rate-limiter'); const limit = rateLimiter.create({ redis: client, key: 'ip', rate: '100/minute' }); // Example usage with an Express-like request object setInterval(() => { limit({ ip: '127.0.0.1' }, (err, rate) => { if (err) { console.error('Rate limiting error:', err); } else if (rate.over) { console.log('Rate limit exceeded. Current:', rate.current); } else { console.log('Request allowed. Remaining:', rate.limit - rate.current); } }); }, 100);
Debug
Known issues
gotchaFixed-window algorithm can allow double the rate at window boundaries (e.g., 100 requests at 00:59 and 100 at 01:01).
fix
Use a sliding window algorithm if bursts at boundaries are unacceptable.
affects: >=0.0.0
gotchaThe key option can be a string ('ip') or a function; using 'ip' automatically extracts the remote address from an HTTP request object.
fix
If using a custom function, ensure it receives the same object passed to limit(). For 'ip', the object must have a 'connection' or 'socket' property with 'remoteAddress'.
affects: >=1.0.0
deprecatedThe package is no longer actively maintained; last update was several years ago.
fix
Consider alternatives like express-rate-limit (with Redis store) or rate-limiter-flexible.
affects: *
Errors
Common errors & fixes
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or not accessible at the specified host/port.
fix
Start Redis server: redis-server, or check the connection options passed to redis.createClient().
TypeError: rateLimiter.create is not a function
The import statement did not correctly load the module (e.g., using ES import with CommonJS-only package).
fix
Use require('redis-rate-limiter') instead of import. The package is CommonJS only.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
redisrequiredRequired to create a Redis client; the library expects a pre-created client instance
Agent activity
6 hits · last 30 days
node
6
Resources
redis-rate-limiter — npm install redis-rate-limiter · libregistry