sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.64k stars 351 forks source link

how many nodes will redis cluster subscriber connect to #564

Closed oronge closed 6 months ago

oronge commented 6 months ago

hello

In ReadMe, I notice RedisCluster keep at least one connection with every master,if I get a Subscriber by method subscriber(),how many connections the Subscriber keep? will it keep connections with every master ?

thanks very much

sewenew commented 6 months ago

subscriber() method randomly picks a node, and creates a connection to it. It does not keep connections to every master. This is a different behavior from RedisCluster.

Regards

oronge commented 6 months ago

subscriber() method randomly picks a node, and creates a connection to it. It does not keep connections to every master. This is a different behavior from RedisCluster.

Regards

thanks for your reply

you said subscriber() method randomly picks a node, and creates a connection to it,is this means the node may be a master or a slave ?

sewenew commented 6 months ago

It depends. If you create RedisCluster with MASTER role, then RedisCluster::subscriber creates connection to a random master. If you create it with SLAVE role, then RedisCluster::subscriber creates connection to a random slave.

Regards

oronge commented 6 months ago

It depends. If you create RedisCluster with MASTER role, then RedisCluster::subscriber creates connection to a random master. If you create it with SLAVE role, then RedisCluster::subscriber creates connection to a random slave.

Regards

thanks

if the connection between Subscriber and node is broken, will the Subscriber try to connect to the node in the future ?

sewenew commented 6 months ago

So far, NO, it won't reconnect. As the doc mentioned, once you get an exception, you need to create a new Subscriber.

oronge commented 6 months ago

get, thank you for your reply!