@routup/rate-limit-redis
Version:
Red adapter for the routup rate-limit plugin.
67 lines (47 loc) • 1.96 kB
Markdown
[](https://badge.fury.io/js/@routup%2Frate-limit-redis)
[](https://github.com/Tada5hi/routup/actions/workflows/main.yml)
[](https://codecov.io/gh/tada5hi/routup)
[](https://snyk.io/test/github/Tada5hi/routup)
[](https://conventionalcommits.org)
This is a redis adapter for the rate-limit plugin.
**Table of Contents**
- [Installation](
- [Documentation](
- [Usage](
- [License](
```bash
npm install @routup/rate-limit-redis --save
```
To read the docs, visit [https://routup.net](https://routup.net)
```typescript
import { createServer } from 'node:http';
import {
createNodeDispatcher,
Router
} from 'routup';
import { rateLimit } from '@routup/rate-limit';
import { RedisStore } from '@routup/rate-limit-redis';
const router = new Router();
// Apply the rate limiting middleware to API calls only
router.use('/api', rateLimit({
// 15 minutes
windowMs: 15 * 60 * 1000,
// Limit each IP to 100 requests
// per `window` (here, per 15 minutes)
max: 100,
// connection string or ioredis instance
// can be passed optional as argument
store: new RedisStore(),
}));
const server = createServer(createNodeDispatcher(router));
server.listen(3000);
```
Made with 💚
Published under [MIT License](./LICENSE).
This library is heavily inspired by
[](https://www.npmjs.com/package/express-rate-limit-redis).