1.0.0 • Published 8 years ago

last-word v1.0.0

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

Last Word

promise based redis request limiter

Build Status

    npm install last-word --save

Usage example

const ms = require('ms');
const lastWord = require('last-word')({
    limit: 3, // number of request before blocked
    timeLimit: ms('1s'), // time in milliseconds when number of requests are cleared
    blockTime: ms('2s'), // block time when
    client: client, // instance of the redis client
    message: 'Limit Reached', // Your custom error message
    Error: YourNewAwesomeError, // Your custom error type
});

app.get('/message', function(req, res, next){
    const key = 'spam_' + req.user.id;
    lastWord(key).then(function() {
        // do your magic here
    }).catch(next);
});

Options that Last Word accepts

NameDescriptionDefault
client(required)instance of the redis clientnull
limitNumber of request before blocked10
timeLimittime in milliseconds when number of requests are clearedms('30s')
blockTimeHow long request key will be blocked, after reaching the limitms('5m')
messageCustom error messageRequest limit reached
ErrorCustom error typeError

Licence

MIT

Name

name is taken from one of the spells of dota 2 silencer hero