Last Word
promise based redis request limiter
npm install last-word --save
Usage example
const ms = require('ms');
const lastWord = require('last-word')({
limit: 3,
timeLimit: ms('1s'),
blockTime: ms('2s'),
client: client,
message: 'Limit Reached',
Error: YourNewAwesomeError,
});
app.get('/message', function(req, res, next){
const key = 'spam_' + req.user.id;
lastWord(key).then(function() {
}).catch(next);
});
Options that Last Word accepts
Name | Description | Default |
---|
client(required) | instance of the redis client | null |
limit | Number of request before blocked | 10 |
timeLimit | time in milliseconds when number of requests are cleared | ms('30s') |
blockTime | How long request key will be blocked, after reaching the limit | ms('5m') |
message | Custom error message | Request limit reached |
Error | Custom error type | Error |
Licence
MIT
Name
name is taken from one of the spells of dota 2 silencer hero