【问题标题】:Error being thrown on reconnection after disconnection in node-redis client在 node-redis 客户端断开连接后重新连接时抛出错误
【发布时间】:2022-01-24 12:51:01
【问题描述】:

我不明白下面代码中引发SocketClosedUnexpectedlyError 错误的原因是什么:

const redisClient = require('redis').createClient();

redisClient.connect().then(function() {
  return redisClient.disconnect();
})
.then(function() {
  redisClient.connect();
});

如果我将第二个 redisClient.connect() 调用包装在 setTimeout() 调用中,如下所示,错误似乎消失了:

const redisClient = require('redis').createClient();

redisClient.connect().then(function() {
  return redisClient.disconnect();
})
.then(function() {
  setTimeout(function() {
    redisClient.connect();
  }, 0);
});

谁能解释一下上面抛出错误的原因是什么? @node-redis 的文档不足以解释这一点。

【问题讨论】:

    标签: javascript node.js redis runtime-error node-redis


    【解决方案1】:

    【讨论】:

    • 所以这是一个错误,我认为您已经纠正了它。不是吗?无论如何,谢谢...
    • 我应该使用 npm 重新安装 node-redis 来解决这个问题吗?
    • @coderboy 将于下周发布 4.0.2 版本,在那之前你可以使用queueMicrotask/setTimeout 来解决这个问题
    • 即使在 v4.0.4 上我仍然会收到此错误。我们究竟如何使用queueMicrotask/setTimeout 作为@LeibaleEidelman 的解决方法?
    • 等一下,刚刚意识到 typeorm(我使用 redis 缓存的方式)具有"redis": "^3.1.1" 的对等依赖项,因此它不是最新的。所以同样的问题@LeibaleEidelman 我如何使用queueMicrotask/setTimeout 作为解决方法?谢谢
    猜你喜欢
    • 2014-12-16
    • 1970-01-01
    • 2012-10-12
    • 2012-10-02
    • 2012-04-14
    • 2022-11-07
    • 1970-01-01
    • 1970-01-01
    • 2017-09-29
    相关资源
    最近更新 更多