Skip to content

Nullmage/express-throttle-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-throttle-redis

Redis wrapper for express-throttle

npm version

Installation

$ npm install express-throttle-redis

Usage

var express = require("express");
var throttle = require("express-throttle");
var redis = require("redis");
var RedisStore = require("express-throttle-redis");

var app = express();

// Rolling window
app.post("/search", throttle({
  "burst": 10,
	"rate": "5/s",
	"store": new RedisStore(redis.createClient())
}), function(req, res, next) {
	// ...
})

// Fixed window
app.post("/search", throttle({
  "burst": 10,
  "period": "1min",
  "store": new RedisStore(redis.createClient())
}), function(req, res, next) {
  // ...
})

Neither express-throttle nor express-throttle-redis will expire / remove / cleanup any keys. This means that memory usage will grow unbounded as new requests are being processed. Thus, it is recommended to have a separate redis instance only for throttling purposes with a sensible maxmemory setting and maxmemory-policy set to allkeys-lru. Furthermore, you may want to disable the persistence layer altogether. Consult the Redis documentation for more information.

About

Redis wrapper for express-throttle

Resources

License

Stars

Watchers

Forks

Packages

No packages published