the1plummie
the1plummie

Reputation: 790

How to set read timeout on node redis client?

On github I don't see an option for read timeout, https://github.com/NodeRedis/node_redis

There's connect_timeout, but that's for making the connection, not about reading/writing tho.

Upvotes: 7

Views: 18174

Answers (2)

You can try the tricks mentioned in the other answer if you really want some timeout value for a particular method (GET in your case), but if your issue is because the method just hangs instead of throwing an exception when it cant connect to the server, you can set enable_offline_queue to false. This will make all Redis commands throw an exception immediately so you can continue with your remaining code instead of waiting for the current command to timeout (the default for Node Redis is 60 minutes, it keeps retrying connections for 1 hour).

Do keep in mind that, with enable_offline_queue set to false, the commands that you issue while there's some connection issue with the server will never be executed.

Upvotes: 2

Ofir Luzon
Ofir Luzon

Reputation: 10907

There is no built it option, but you can wrap your call with a timeout handler. See the question here, and the linked answer gist here.

Upvotes: 1

Related Questions