简体   繁体   English

在 node-redis 客户端断开连接后重新连接时抛出错误

[英]Error being thrown on reconnection after disconnection in node-redis client

I couldn't understand what's the reason for the SocketClosedUnexpectedlyError error fired in the code below:我不明白下面代码中引发的SocketClosedUnexpectedlyError错误的原因是什么:

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

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

If I wrap the second redisClient.connect() call inside a setTimeout() call, as shown below, the error seems to go away:如果我将第二个redisClient.connect()调用包装在setTimeout()调用中,如下所示,则错误似乎远离 go:

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

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

Can anyone please explain what's the reason for the error thrown above?谁能解释一下上面抛出错误的原因是什么? The documentation of @node-redis isn't good enough to explain this. @node-redis的文档不足以解释这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM