rate-limit-redis is a Redis-backed storage engine designed for the `express-rate-limit` middleware, enabling distributed rate limiting across multiple application instances. It is currently at stable version 4.3.1, with frequent minor and patch releases, as indicated by the recent changelog entries, reflecting an active maintenance schedule. This library supports popular Redis clients such as `node-redis` and `ioredis`, and also explicitly lists compatibility with `redict` and `valkey`, offering flexibility in deployment. A key differentiator is its flexible `sendCommand` abstraction, which allows seamless integration with various Redis client libraries by adapting their specific command execution functions. It requires Node.js 16 or above and Redis 2.6.12 or above for operation. The project maintains an active development status, ensuring compatibility with the latest `express-rate-limit` versions and modern Node.js environments.
npm install rate-limit-redisVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up an Express application with rate limiting using Redis as a store, configured with the node-redis client. It connects to Redis and applies the rate limiter to all routes.
Upgrade your Node.js runtime environment to version 16 or later.
Update your `express-rate-limit` package to version 7 or newer in your project's dependencies.
Ensure your Redis server instance is running version 2.6.12 or newer.
Upgrade to version 4.1.1 or later to ensure `store.get()` consistently returns `0` when no hits are recorded for a client.
Ensure you call `await client.connect()` after creating your Redis client instance and before passing it to the `RedisStore` constructor.
For ES Modules, set `"type": "module"` in your `package.json` and use `import`. For CommonJS, ensure `"type": "commonjs"` (or no `type` field) and use `require()`. Ensure bundlers or TypeScript configurations handle module resolution correctly.
Adjust the `sendCommand` function's signature or cast its return value to `Promise<number>` or `number` to match the expected type. For `ioredis`, you might cast `client.call(...) as Promise<number>`.
Verify that your Redis client object is properly initialized and connected, and that the `sendCommand` function within `RedisStore`'s options correctly references a valid command sending method on that client (e.g., `client.sendCommand(args)` or `client.call(command, ...args)`).