It does not work
See original GitHub issueit is just does not work for this simple koa app: `const Koa = require(‘koa’); const ratelimit = require(‘koa-ratelimit’); const Promise = require(‘bluebird’); const redis = require(‘redis’);
const redisOption = {}; const redisClient = redis.createClient(redisOption); Promise.promisifyAll(redis.RedisClient.prototype); Promise.promisifyAll(redis.Multi.prototype); redisClient.once(‘ready’, () => { console.log(‘redis connnection ready’); }); redisClient.on(‘error’, (err) => { console.log(‘can't connect to redis’, err); process.exit(1); });
const app = new Koa();
// apply rate limit
app.use(ratelimit({ db: redisClient, duration: 10000, max: 10 }));
// response middleware
app.use(async (ctx) => { ctx.body = ‘Stuff!’; });
app.listen(4000); console.log(‘listening on port 4000’); ` then keep trying send request use postman, right after the duration pass the remaining time will jump to a random num, even with a negative value, e.g.
Rate limit exceeded, retry in -412 ms.
I am using NodeJs v8.11.1, Redis 3.0.0, “koa”: “^2.5.1”, “koa-ratelimit”: “^4.1.2”, “redis”: “^2.8.0”,
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
This issue is mented in Update 09/2020 but it still not working with
node-redis
. And also it’s not problem with koa-ratelimit 😃 https://github.com/microlinkhq/async-ratelimiter/issues/22@cxwcfea https://github.com/animir/node-rate-limiter-flexible works with
redis
andioredis
as well