koajs / ratelimit

Rate limiter middleware
MIT License
485 stars 57 forks source link

It does not work #40

Closed cxwcfea closed 3 years ago

cxwcfea commented 6 years ago

it 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",

andreyrd commented 5 years ago

You need to be using "ioredis", not "redis".

animir commented 5 years ago

@cxwcfea https://github.com/animir/node-rate-limiter-flexible works with redis and ioredis as well

koalex commented 3 years ago

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

3imed-jaberi commented 3 years ago

Hi guys, I fixed the missing behave in async-ratelimiter and now everything work just I wait @niftylettuce to merge my PR #62 and everything done 🎉.

niftylettuce commented 3 years ago

v5.0.1 released to npm

https://github.com/koajs/ratelimit/releases/tag/v5.0.1