@@ -49,8 +49,8 @@ sentinel::~sentinel(void) {
4949}
5050
5151sentinel&
52- sentinel::add_sentinel (const std::string& host, std::size_t port) {
53- m_sentinels.push_back ({host, port});
52+ sentinel::add_sentinel (const std::string& host, std::size_t port, std:: uint32_t timeout_msecs ) {
53+ m_sentinels.push_back ({host, port, timeout_msecs });
5454 return *this ;
5555}
5656
@@ -62,9 +62,8 @@ sentinel::clear_sentinels() {
6262bool
6363sentinel::get_master_addr_by_name (const std::string& name, std::string& host, std::size_t & port, bool autoconnect) {
6464 // ! reset connection settings
65- host.clear ();
66- port = 0 ;
67- std::uint32_t connect_timeout = 2000 ;
65+ host = " " ;
66+ port = 0 ;
6867
6968 // ! we must have some sentinels to connect to if we are in autoconnect mode
7069 if (autoconnect && m_sentinels.size () == 0 ) {
@@ -79,7 +78,7 @@ sentinel::get_master_addr_by_name(const std::string& name, std::string& host, st
7978 if (autoconnect) {
8079 try {
8180 // ! Will round robin all attached sentinels until it finds one that is online.
82- connect_sentinel (connect_timeout, nullptr );
81+ connect_sentinel (nullptr );
8382 }
8483 catch (const redis_error&) {
8584 }
@@ -95,8 +94,8 @@ sentinel::get_master_addr_by_name(const std::string& name, std::string& host, st
9594 send ({" SENTINEL" , " get-master-addr-by-name" , name}, [&](cpp_redis::reply& reply) {
9695 if (reply.is_array ()) {
9796 auto arr = reply.as_array ();
98- host = arr[0 ].as_string (); // host
99- port = std::stoi (arr[1 ].as_string (), nullptr , 10 ); // port
97+ host = arr[0 ].as_string ();
98+ port = std::stoi (arr[1 ].as_string (), nullptr , 10 );
10099 }
101100 });
102101 sync_commit ();
@@ -111,7 +110,7 @@ sentinel::get_master_addr_by_name(const std::string& name, std::string& host, st
111110}
112111
113112void
114- sentinel::connect_sentinel (std:: uint32_t timeout_msecs, const sentinel_disconnect_handler_t & sentinel_disconnect_handler) {
113+ sentinel::connect_sentinel (const sentinel_disconnect_handler_t & sentinel_disconnect_handler) {
115114 if (m_sentinels.size () == 0 ) {
116115 throw redis_error (" No sentinels available. Call add_sentinel() before connect_sentinel()" );
117116 }
@@ -126,10 +125,10 @@ sentinel::connect_sentinel(std::uint32_t timeout_msecs, const sentinel_disconnec
126125 while (not_connected && it != m_sentinels.end ()) {
127126 try {
128127 __CPP_REDIS_LOG (debug, std::string (" cpp_redis::sentinel attempting to connect to host " ) + it->get_host ());
129- m_client.connect (it->get_host (), it->get_port (), disconnect_handler, receive_handler, timeout_msecs );
128+ m_client.connect (it->get_host (), it->get_port (), disconnect_handler, receive_handler, it-> get_timeout_msecs () );
130129 }
131130 catch (const redis_error&) {
132- not_connected = true ; // Connection failed.
131+ not_connected = true ; // ! Connection failed.
133132 __CPP_REDIS_LOG (info, std::string (" cpp_redis::sentinel unable to connect to sentinel host " ) + it->get_host ());
134133 }
135134
@@ -232,6 +231,16 @@ sentinel::is_connected(void) {
232231 return m_client.is_connected ();
233232}
234233
234+ const std::vector<sentinel::sentinel_def>&
235+ sentinel::get_sentinels (void ) const {
236+ return m_sentinels;
237+ }
238+
239+ std::vector<sentinel::sentinel_def>&
240+ sentinel::get_sentinels (void ) {
241+ return m_sentinels;
242+ }
243+
235244sentinel&
236245sentinel::send (const std::vector<std::string>& redis_cmd, const reply_callback_t & callback) {
237246 std::lock_guard<std::mutex> lock_callback (m_callbacks_mutex);
0 commit comments