Closed cxwcfea closed 3 years ago
You need to be using "ioredis", not "redis".
@cxwcfea https://github.com/animir/node-rate-limiter-flexible works with redis
and ioredis
as well
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
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 🎉.
v5.0.1 released to npm
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",