🐛 Bug Report # Redis expire not working
I setup redis on rate-limit options, but it does not sets TTL ( expire )
- node version: 16
- fastify version: >=3.0.0
- os: Mac
Can you add an example to reproduce?
It creates key in redis without TTL ( -1 ), so it doesnt expire and blocks permanently ( see image link below)
const fastify = require('fastify')({
logger: {
level: 'info' // Will use pino.destination()
}
});
const crypto = require('crypto');
const redis = require('./init-redis')
fastify.register(require('fastify-rate-limit'), {
/* ... */
keyGenerator: function(req) {
return req.user ? req.user.username : crypto.createHash('md5').update(req.headers['ip'] || 'unknown' + req.headers['user-agent'] || 'unknown').digest('hex')
},
skipOnError: true,
redis,
global: true, max: 100, timeWindow: '1 minute'
})
As you can see in https://github.com/fastify/fastify-rate-limit/blob/master/store/RedisStore.js, we are calling pexpire.
Please include a runnable example to reproduce your problem (something I can run with node file.js). I'd also be very happy if you could send a PR fixing this.
@aligzl I experienced the same thing and it worked for me after I passed the time in ms as an integer instead of a string.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.