I couldn't understand what's the reason for the SocketClosedUnexpectedlyError error fired in the code below:
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:
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.
It's a bug in node-redis v4...
https://github.com/redis/node-redis/issues/1801
https://github.com/redis/node-redis/commit/74daee302338cf2fcc1bb48aeac02be828e0c6d7