Registry / storage / tokenthrottle-redis

tokenthrottle-redis

JSON →
library1.2.0jsnpmunverified

Redis-backed distributed rate limiting implementation for the tokenthrottle interface. Stable version 1.2.0, with low release cadence. Provides shared rate limiting across multiple servers/processes using Redis as backend. Unlike local-only throttles, it supports atomic operations via Redis to maintain consistency. Requires ioredis or redis client. Expires unused tokens to save memory.

npm install tokenthrottle-redis
INSTALL
IMPORT
SIG · TOKENTHROTTLE-REDI
T
tokenthrottle-redis
storagejavascriptv1.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.

default
import throttle from 'tokenthrottle-redis'
const { throttle } = require('tokenthrottle-redis')
The module exports a factory function. Use default import or const ... = require('...'). Named destructuring fails.
require
const throttle = require('tokenthrottle-redis')(options, redisClient)
const { throttle } = require('tokenthrottle-redis')
Module is CommonJS; call the returned factory function with options and client.
TypeScript
import throttle from 'tokenthrottle-redis'
import * as throttle from 'tokenthrottle-redis'
No types bundled; use @types/tokenthrottle-redis if available or declare module.

Creates a Redis-backed throttle (100 req/s) and uses it as Express rate-limiting middleware.

const redis = require('redis'); const redisClient = redis.createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' }); const throttle = require('tokenthrottle-redis')({ rate: 100, expiry: 86400 }, redisClient); // Middleware example for Express function rateLimitMiddleware(req, res, next) { const id = req.ip; // or req.user.id throttle.rateLimit(id, (err, limited) => { if (err) return next(err); if (limited) { return res.status(429).json({ error: 'Rate limit exceeded, please slow down.' }); } next(); }); } // Usage const express = require('express'); const app = express(); app.use(rateLimitMiddleware); app.listen(3000);
Debug
Known issues
breakingredis package breaking changes: v4 dropped callback support and changed createClient signature. Must use v3 (2.x) or adapt.
fix
Use redis@3 or newer version with async/await and promise-based API; wrap client as needed.
affects: >=1.0.0
gotchatokenthrottle-redis uses Lua scripts for atomic increments; requires Redis 2.6+ (EVAL command).
fix
Ensure Redis server version is >=2.6 or use a compatible alternative.
affects: >=1.0.0
deprecatedtokenthrottle package is unmaintained; alternatives like express-rate-limit with Redis store are recommended.
fix
Migrate to a maintained rate limiter like express-rate-limit or rate-limiter-flexible.
affects: >=1.0.0
gotchaDefault prefix 'redisThrottle' may conflict with other apps using same Redis instance.
fix
Set a unique prefix in options: { prefix: 'myapp:throttle' }.
affects: >=1.0.0
Errors
Common errors & fixes
Error: The 'options' argument must be an object
Calling the factory function without arguments or with wrong type.
fix
Pass an object with required properties: throttle({ rate: 100 })
TypeError: redisClient.rateLimit is not a function
Using the returned value directly without calling rateLimit method, or misimport.
fix
Ensure you create throttle with require('tokenthrottle-redis')(options, redisClient) and call throttle.rateLimit(id, callback).
Error: EVAL command not supported
Redis server version <2.6 does not support Lua scripting.
fix
Upgrade Redis to >=2.6 or use a different rate limiter that does not require EVAL.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
tokenthrottlerequiredCore rate limiting logic; this package provides Redis backend implementation
redisrequiredRedis client for token storage and atomic operations
Agent activity
31 hits · last 30 days
node
26
OpenAI (training)
1
Resources
tokenthrottle-redis — npm install tokenthrottle-redis · libregistry