0.0.4 • Published 8 years ago

express-throttle-redis v0.0.4

Weekly downloads
13
License
MIT
Repository
github
Last release
8 years ago

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.