@nestjs-redisx/rate-limit
v1.0.2
Published
Rate limiting plugin for NestJS RedisX with multiple algorithms (fixed-window, sliding-window, token-bucket)
Downloads
182
Maintainers
Readme
@nestjs-redisx/rate-limit
Rate limiting plugin for NestJS RedisX. Supports fixed window, sliding window, and token bucket algorithms with a declarative @RateLimit decorator and automatic X-RateLimit-* response headers.
Installation
npm install @nestjs-redisx/core @nestjs-redisx/rate-limit ioredisQuick Example
import { RedisModule } from '@nestjs-redisx/core';
import { RateLimitPlugin, RateLimit } from '@nestjs-redisx/rate-limit';
@Module({
imports: [
RedisModule.forRoot({
clients: { host: 'localhost', port: 6379 },
plugins: [new RateLimitPlugin({ defaultPoints: 100, defaultDuration: 60 })],
}),
],
})
export class AppModule {}
@Controller('api')
export class ApiController {
@Get('data')
@RateLimit({ points: 10, duration: 60 })
getData() {
return { data: 'value' };
}
}Documentation
Full documentation: nestjs-redisx.dev/en/reference/rate-limit/
License
MIT
