skip to Main Content

I am running my nodejs application on google cloudrun. My application connects to google memorystore redis. Every few mins am getting the following error

Error: read Connection Reset

Followed by

AbortError: Redis connection lost and command aborted. It might have been processed.

Please help what am I missing?

My nodejs code

const redis = require('redis')

const redisClient = redis.createClient({host:'xxx', port: 6379})
redisClient.on('error, function (err) {
console.log(err)
}

const data = await redisClient.getExAsync('key') 

2

Answers


  1. Use "setInterval" function in order to invoke Redis operation every minute.

    async function RedisKA() {
      client.get("key2", (err, reply) => {
        console.log(`${kaCount} redis keep `);
      });
    
    }
    
    let updateIntervalId = setInterval(RedisKA, 60000);
    

    If you want to avoid the request timeout on the Cloud Run side, which is 5 minutes by default then set your value based on your requirement.

    Login or Signup to reply.
  2. The issue may be caused due a socket time out. This is expected to happen when there is no activity for a period of time.

    This could be avoided by periodically executing any command on the connection, for example one command per minute, so it will keep the socket alive and will not abort the connection.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search