26 #include <condition_variable> 30 #include <cpp_redis/misc/logger.hpp> 31 #include <cpp_redis/network/redis_connection.hpp> 43 #ifndef __CPP_REDIS_USE_CUSTOM_TCP_CLIENT 53 explicit sentinel(
const std::shared_ptr<network::tcp_client_iface>& tcp_client);
78 sentinel&
send(
const std::vector<std::string>& sentinel_cmd,
const reply_callback_t& callback =
nullptr);
102 template <
class Rep,
class Period>
107 std::unique_lock<std::mutex> lock_callback(m_callbacks_mutex);
108 __CPP_REDIS_LOG(debug,
"cpp_redis::sentinel waiting for callbacks to complete");
109 if (!m_sync_condvar.wait_for(lock_callback, timeout, [=] {
110 return m_callbacks_running == 0 && m_callbacks.empty();
112 __CPP_REDIS_LOG(debug,
"cpp_redis::sentinel finished waiting for callback");
115 __CPP_REDIS_LOG(debug,
"cpp_redis::sentinel timed out waiting for callback");
129 sentinel&
add_sentinel(
const std::string& host, std::size_t port, std::uint32_t timeout_msecs = 0);
142 void disconnect(
bool wait_for_removal =
false);
161 void connect_sentinel(
const sentinel_disconnect_handler_t& disconnect_handler =
nullptr);
172 const std::string& host,
174 const sentinel_disconnect_handler_t& disconnect_handler =
nullptr,
175 std::uint32_t timeout_msecs = 0);
191 const std::string& name,
194 bool autoconnect =
true);
197 sentinel& ckquorum(
const std::string& name,
const reply_callback_t& reply_callback =
nullptr);
198 sentinel& failover(
const std::string& name,
const reply_callback_t& reply_callback =
nullptr);
199 sentinel& flushconfig(
const reply_callback_t& reply_callback =
nullptr);
200 sentinel& master(
const std::string& name,
const reply_callback_t& reply_callback =
nullptr);
201 sentinel& masters(
const reply_callback_t& reply_callback =
nullptr);
202 sentinel& monitor(
const std::string& name,
const std::string& ip, std::size_t port, std::size_t quorum,
const reply_callback_t& reply_callback =
nullptr);
203 sentinel& ping(
const reply_callback_t& reply_callback =
nullptr);
204 sentinel&
remove(
const std::string& name,
const reply_callback_t& reply_callback =
nullptr);
205 sentinel& reset(
const std::string& pattern,
const reply_callback_t& reply_callback =
nullptr);
206 sentinel& sentinels(
const std::string& name,
const reply_callback_t& reply_callback =
nullptr);
207 sentinel&
set(
const std::string& name,
const std::string& option,
const std::string& value,
const reply_callback_t& reply_callback =
nullptr);
208 sentinel& slaves(
const std::string& name,
const reply_callback_t& reply_callback =
nullptr);
218 sentinel_def(
const std::string& host, std::size_t port, std::uint32_t timeout_msecs)
219 : m_host(host), m_port(port), m_timeout_msecs(timeout_msecs) {}
264 std::uint32_t m_timeout_msecs;
297 void call_disconnect_handler(
void);
302 void clear_callbacks(
void);
308 void try_commit(
void);
314 std::vector<sentinel_def> m_sentinels;
324 std::queue<reply_callback_t> m_callbacks;
329 sentinel_disconnect_handler_t m_disconnect_handler;
334 std::mutex m_callbacks_mutex;
339 std::condition_variable m_sync_condvar;
344 std::atomic<unsigned int> m_callbacks_running;
sentinel & add_sentinel(const std::string &host, std::size_t port, std::uint32_t timeout_msecs=0)
Definition: redis_connection.hpp:45
Definition: sentinel.hpp:215
size_t get_port(void) const
Definition: sentinel.hpp:235
void set_timeout_msecs(std::uint32_t timeout_msecs)
Definition: sentinel.hpp:248
const std::vector< sentinel_def > & get_sentinels(void) const
sentinel & operator=(const sentinel &)=delete
assignment operator
std::uint32_t get_timeout_msecs(void) const
Definition: sentinel.hpp:241
void connect(const std::string &host, std::size_t port, const sentinel_disconnect_handler_t &disconnect_handler=nullptr, std::uint32_t timeout_msecs=0)
const std::string & get_host(void) const
Definition: sentinel.hpp:229
void disconnect(bool wait_for_removal=false)
sentinel & send(const std::vector< std::string > &sentinel_cmd, const reply_callback_t &callback=nullptr)
std::function< void(reply &)> reply_callback_t
Definition: sentinel.hpp:67
Definition: sentinel.hpp:40
~sentinel_def(void)=default
dtor
sentinel & sync_commit(const std::chrono::duration< Rep, Period > &timeout)
Definition: sentinel.hpp:104
sentinel & sync_commit(void)
std::function< void(sentinel &)> sentinel_disconnect_handler_t
Definition: sentinel.hpp:153
bool get_master_addr_by_name(const std::string &name, std::string &host, std::size_t &port, bool autoconnect=true)
void clear_sentinels(void)
void connect_sentinel(const sentinel_disconnect_handler_t &disconnect_handler=nullptr)
sentinel_def(const std::string &host, std::size_t port, std::uint32_t timeout_msecs)
ctor
Definition: sentinel.hpp:218
sentinel(void)
ctor & dtor
Definition: array_builder.hpp:29