Reputation: 705
I am having an issue where i have a long running node socket server which uses redis to store data. The problem seems to be when the socket server isn't being used for a while and contacting redis, the connection to redis is dropped off.
I read that the following would work to keep the connection alive:
const redisClient = redis.createClient({
url: process.env.REDIS_HOST
})
redisClient.on('connect', () => {
const redisStream = redisClient.stream;
redisStream.setKeepAlive(true, 30000);
})
However this doesn't work in redis version 4.1.0, i get this following error:
TypeError: Cannot read properties of undefined (reading 'setKeepAlive')
It seems the redis client doesn't have a method setKeepAlive
Any ideas? I can't find anything in the documentation about this. Is there another way this is done now, or would it be better if my node app hooks to the redis "end" event and re-connects itself?
Upvotes: 2
Views: 1204
Reputation: 4464
set pingInterval
in createClient()
createClient({
pingInterval: 30000 // 30 s
})
Upvotes: 1