redis / node-redis

Redis Node.js client

Home Page:https://redis.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a connectTimedOut to client.connect()?

dallascao opened this issue · comments

This is a feature request, not a bug report. Sorry for the wrong label.

It would be useful if there is an connectTimedOut option to client.connect() method.

I used redis to remember some switches and redis is not crucial. But when there is a problem with my redis server, client.connect() waits forever.

I would like to be able to do something like this:

try {
 await client.connect({connectTimedOut: 3000})
} catch (error) {
 //ignore this error. My program run well without redis service anyway.
}

You can do it with this config (see client-configuration.md for more details):

createClient({
  socket: {
    connectTimeout: 1000, // in ms, `5000` by default
    reconnectStrategy: () => new Error('do not retry') // by default it'll return `Math.min(retries * 50, 500)`, which means retry forever
  }
});