无法处理 GET。连接尚未建立,离线队列已停用

GET can't be processed. The connection is not yet established and the offline queue is deactivated

在生产中出现以下异常,即使我有 500 毫秒的重试策略和 1 秒的 setTimeout 包装 setAsync 和 getAsync 函数。不确定这里出了什么问题。

AbortError:
   at handle_offline_command (at handle_offline_command (/usr/src/app/node_modules/redis/index.js:779:15)at handle_offline_command (/usr/src/app/node_modules/redis/index.js:779:15): /usr/src/app/node_modules/redis/index.jsat handle_offline_command (/usr/src/app/node_modules/redis/index.js:779:15): 779)

您似乎在连接建立之前发出命令,并且 enableOfflineQueue 设置为 false

您可以通过两种方式解决:

  1. 启用离线队列,命令将在建立连接后排队并发送。
  2. 确保在触发命令之前连接已准备就绪(通过侦听 connect 事件,或使用 .connect 函数的 callback/promise。您可以阅读更多相关信息here).