rate-limit-redis-store
v0.1.10
Published
A Redis store for express rate limiting middlewares.
Downloads
25
Readme
rate-limit-redis-store
A Redis store for express rate limiting middlewares.
This store is compatible with express-rate-limit middleware. And you can also work with Promise.
installation
npm install rate-limit-redis-store --save
## or
yarn add rate-limit-redis-store
usage
const RateLimit = require('express-rate-limit');
const RedisStore = require('rate-limit-redis-store');
const limiter = new RateLimit({
max: 1000,
delayMs: 0,
store: new RedisStore({
// configs
}),
// some other express-rate-limit configs
});
app.use(limiter);
Configurations
- expiryMS: milliseconds - how long to keep records of requests in store. Defaults to
60000
(1 minute). - prefix: String - prefix for entries in Redis. Defaults to
rlstore:
. - client: ioredis Client - a redis client to use. Defaults to
new require('ioredis')()
. - serializer: Serializer - a serializer to use. Defaults to
JSON
. - refreshExpire: bool - should refresh expire time after entries update. Defaults to
false
methods
This store implement incr
, decrement
, resetKey
for express-rate-limit.
You can also use the following methods:
- store#get(rdskey, cb)
- store#getByKey(rdskey, objkey, cb)
- store#sadd(rdskey, value, cb)
- store#scrad(rdskey, cb)
- store#sismember(rdskey, value, cb)
promise
You can use promise in all methods:
store
.incr('_your_key')
.then(res => {
console.log(res); // 1
})
.catch(err =>{
// ...
})
ackn.
License
MIT