如何在节点 redis 客户端上设置读取超时? [英] How to set read timeout on node redis client?

查看:62
本文介绍了如何在节点 redis 客户端上设置读取超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 github 上我没有看到读取超时的选项,https://github.com/NodeRedis/node_redis

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

connect_timeout,但那是为了建立连接,而不是读/写.

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

推荐答案

如果您确实想要某个特定方法的超时值(在您的情况下为 GET),您可以尝试其他答案中提到的技巧,但如果您的问题是由于该方法在无法连接到服务器时只是挂起而不是抛出异常,因此您可以将 enable_offline_queue 设置为 false.这将使所有 Redis 命令立即抛出异常,以便您可以继续执行剩余的代码,而不是等待当前命令超时(Node Redis 的默认值为 60 分钟,它会持续重试连接 1 小时).

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).

请记住,如果 enable_offline_queue 设置为 false,您在服务器出现连接问题时发出的命令将永远不会执行.

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.

这篇关于如何在节点 redis 客户端上设置读取超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆