serbis
serbis

Reputation: 111

Why does connecting to a cluster constantly loop in IoRedis?

I am currently trying to connect to my Redis cluster stored on another instance from a server running my application. I am using IoRedis to interface between my application and my Redis instance and it worked fine when there was only a single Redis node running. However, after trying to setup the cluster connection in my Node application, it constantly loops on the connection. My cluster setup works correctly.

As of now, I have tried the following configuration in my application to connect to the cluster. The issue is that the 'connect' even constantly loops printing out 'Connected to Redis!'. The events for 'ready' and 'error' are never fired.

const cache: Cluster = new Cluster([{
   port: 8000,
   host: REDIS_HOST
}, {
   port: 8001,
   host: REDIS_HOST
}, {
   port: 8002,
   host: REDIS_HOST
}]);

cache.on('connect', () => {
    console.log('Connected to Redis!');
});

In the end, the 'connect' event should only fire once. Does anyone have any thoughts on this?

Upvotes: 5

Views: 1694

Answers (2)

Pax Beach
Pax Beach

Reputation: 2803

My issue is in connecting to different cluster addresses.

I've created cluster on 127.0.0.1

/redis/redis-stable/src/redis-cli -a MyClusterPa$$word --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1 --cluster-yes

And after this I've connected to external server IP 34.35.36.37. Or if I connected by local network address 10.124.0.1 - the same issue, the client permanently reconnecting.

Only connect to cluster by 127.0.0.1 works well in this case.

Because of this cluster configuration:

cat /opt/redis/redis1/nodes.conf

3043cbc19886b09e58376f9d7e51acc491429cd9 172.20.0.31:7001@17001,,tls-port=0,shard-id=8b038b2b898ea64e9825636825eb949a2dcf0a66 myself,master - 0 1692699047374 1 connected 0-5460
8bb5565b8dc2a1e9084f459b14e496d90f22614e 172.20.0.34:7004@17004,,tls-port=0,shard-id=fa4f1ebb76768155d220e25e2a64d1e9d311318d slave 224cf5dae12cb8a81fe22873e39631f3aa6a8af5 0 1692699047512 3 connected
d2a45891b8796b854f0b5999675e0e2beb1084ef 172.20.0.35:7005@17005,,tls-port=0,shard-id=8b038b2b898ea64e9825636825eb949a2dcf0a66 slave 3043cbc19886b09e58376f9d7e51acc491429cd9 0 1692699047602 1 connected
80aa23e58e2387202aa5ee84f4caf2f89c2ebb1d 172.20.0.32:7002@17002,,tls-port=0,shard-id=58ab040ea66aaabe4cf8b2effc97f960f0dc7a4c master - 0 1692699047892 2 connected 5461-10922
0d56e18cc1cae621fa5bb195ea97d4d6a2db3f66 172.20.0.36:7006@17006,,tls-port=0,shard-id=58ab040ea66aaabe4cf8b2effc97f960f0dc7a4c slave 80aa23e58e2387202aa5ee84f4caf2f89c2ebb1d 1692699047898 1692699047374 2 connected
224cf5dae12cb8a81fe22873e39631f3aa6a8af5 172.20.0.33:7003@17003,,tls-port=0,shard-id=fa4f1ebb76768155d220e25e2a64d1e9d311318d master - 0 1692699047801 3 connected 10923-16383
vars currentEpoch 6 lastVoteEpoch 0

Upvotes: 0

DevTheJo
DevTheJo

Reputation: 2487

This kind of error, as I discovered it today, is not related to ioredis but to the redis instance setup. In my case, the problem I had with p3x-redis-ui, which use ioredis, it was the cluster that was not initialized. See https://github.com/patrikx3/redis-ui/issues/48 maybe you'll find any clues to help you resolve your bug.

Upvotes: 0

Related Questions