Open HelloKevinTian opened 4 years ago
It might be because ioredis will try to connect upon using new IORedis.Cluster()
by the point you're adding a listener the error event might have already been emitted.
You could try adding lazyConnect: true
to the options, adding the listeners and then doing an start to see if that's the problem
I'm using lazyConnect: true
and I noticed, if the connection is already established and I then close the Redis server, ioredis keeps spamming unhandled error event
even though I have a listener on error
Also having this issue, but with lazyConnect: true already set
I'm using
lazyConnect: true
and I noticed, if the connection is already established and I then close the Redis server, ioredis keeps spammingunhandled error event
even though I have a listener onerror
I also have this problem!!
Does adding a disconnect to the error handler fix the issue?
This should work, I also fixed a few typos.
const IORedis = require('ioredis');
let cluster = new IORedis.Cluster([{
host: '192.168.1.71',
port: 7000
}, {
host: '192.168.1.71',
port: 7001
}, {
host: '192.168.1.71',
port: 7002
}], {
clusterRetryStrategy: function() {
let delay = Math.min(2000 + times * 50, 10000);
return delay;
}
});
cluster.on('connect', function() {
console.log(`Redis Cluster connected `);
});
cluster.on('error', function(err) {
cluster.disconnect();
console.error('Redis Cluster error', err);
});
have you all solved this issue? I am having the same issue. Although I try to catch the error with on('error')
, the whole node application exited when the connection is unsuccessful. Would be nice to have some workaround for this :D thanks!
Update:
I tried to wrap the whole connection code in try catch
and it is also not working..
Can you see if my PR #1501 helps you? I think #1500 may be a similar issue.
Hi,I am trying to connect redis cluster by ioredis.
node version: 10.19.0 ioredis: 4.16.3
I met "Unhandled 'error' event" error message and my application crashed when I disconnect from the network.
Actually I have listened the "error event" in my code,but I still met the error.
My code is as follows.