A small library providing throttling methods
npm install trottola --save
var trottola = require('trottola');
var redis = require('redis');
var client = redis.createClient(); // Used to store client information
var clientPub = redis.createClient(); // Used internally to set the throttling event timer
var clientSub = redis.createClient(); // Used internally to be notified of the throttling event
throttler = trottola({
limit: 50,
timeFrame: 600,
redis: client,
redisPub: clientPub,
redisSub: clientSub
});
this.throttler.availableRequests("test", function(available, result) {
var now = (new Date()).getTime() / 1000;
console.log('limit: ' + result.limit);
console.log('used: ' + result.used);
console.log('reset: ' + result.reset);
if (!available) {
// Request limit reached
} else {
// Request limit not reached
}
console.log("reset in " + Math.round(result.reset - now));
}
npm test
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
- 0.1.3 - Fix: adapting the code to an API change in dtimer
- 0.1.2 - Updated dtimer to fix an issue with Redis connections
- 0.1.1 - README.md fix
- 0.1.0 - Initial release