Skip to content

A rate limiting store for express-rate-limit with Redis

Notifications You must be signed in to change notification settings

knoxcard2/rate-limit-redis

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rate Limit Redis

Build Status NPM version Dependency Status Development Dependency Status

Redis client for the express-rate-limit middleware.

Install

$ npm install --save rate-limit-redis

Usage

var RateLimit = require('express-rate-limit');
var RedisStore = require('rate-limit-redis');

var limiter = new RateLimit({
  store: new RedisStore({
    // see Configuration
  }),
  max: 100, // limit each IP to 100 requests per windowMs
  delayMs: 0 // disable delaying - full speed until the max limit is reached
});

//  apply to all requests
app.use(limiter);

Connect to UDP Socket

var RateLimit = require('express-rate-limit');
var RedisStore = require('rate-limit-redis');
var Redis = require('ioredis');
var client = new Redis('/tmp/redis.sock');

var limiter = new RateLimit({
  store: new RedisStore({
    client: client,
  }),
  max: 100, // limit each IP to 100 requests per windowMs
  delayMs: 0 // disable delaying - full speed until the max limit is reached
});

Configuration

  • expiry: seconds - how long each rate limiting window exists for. Defaults to 60.
  • resetExpiryOnChange: boolean - if the expiry time should be reset every time a key is incremented/decremented. This means that when the limit is reached and the user is given a 429 response, the rate limit window is extended. Defaults to false.
  • prefix: string - prefix to add to entries in Redis. Defaults to rl:.
  • client: Redis Client or ioredis Client- A Redis Client to use. Defaults to require('redis').createClient();.

License

MIT © Wyatt Johnson, Nathan Friedly

About

A rate limiting store for express-rate-limit with Redis

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%