![]() |
cpp_redis
4.0.0
cpp_redis is a C++11 Asynchronous Multi-Platform Lightweight Redis Client, with support for synchronous operations and pipelining.
|
#include <sentinel.hpp>
Classes | |
| class | sentinel_def |
Public Types | |
| typedef std::function< void(reply &)> | reply_callback_t |
| typedef std::function< void(sentinel &)> | sentinel_disconnect_handler_t |
Public Member Functions | |
| sentinel (void) | |
| ctor & dtor More... | |
| sentinel (const std::shared_ptr< network::tcp_client_iface > &tcp_client) | |
| ~sentinel (void) | |
| dtor | |
| sentinel (const sentinel &)=delete | |
| copy ctor | |
| sentinel & | operator= (const sentinel &)=delete |
| assignment operator | |
| sentinel & | send (const std::vector< std::string > &sentinel_cmd, const reply_callback_t &callback=nullptr) |
| sentinel & | commit (void) |
| sentinel & | sync_commit (void) |
| template<class Rep , class Period > | |
| sentinel & | sync_commit (const std::chrono::duration< Rep, Period > &timeout) |
| sentinel & | add_sentinel (const std::string &host, std::size_t port, std::uint32_t timeout_msecs=0) |
| void | clear_sentinels (void) |
| void | disconnect (bool wait_for_removal=false) |
| bool | is_connected (void) |
| void | connect_sentinel (const sentinel_disconnect_handler_t &disconnect_handler=nullptr) |
| void | connect (const std::string &host, std::size_t port, const sentinel_disconnect_handler_t &disconnect_handler=nullptr, std::uint32_t timeout_msecs=0) |
| bool | get_master_addr_by_name (const std::string &name, std::string &host, std::size_t &port, bool autoconnect=true) |
| sentinel & | ckquorum (const std::string &name, const reply_callback_t &reply_callback=nullptr) |
| sentinel & | failover (const std::string &name, const reply_callback_t &reply_callback=nullptr) |
| sentinel & | flushconfig (const reply_callback_t &reply_callback=nullptr) |
| sentinel & | master (const std::string &name, const reply_callback_t &reply_callback=nullptr) |
| sentinel & | masters (const reply_callback_t &reply_callback=nullptr) |
| 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) |
| sentinel & | ping (const reply_callback_t &reply_callback=nullptr) |
| sentinel & | remove (const std::string &name, const reply_callback_t &reply_callback=nullptr) |
| sentinel & | reset (const std::string &pattern, const reply_callback_t &reply_callback=nullptr) |
| sentinel & | sentinels (const std::string &name, const reply_callback_t &reply_callback=nullptr) |
| sentinel & | set (const std::string &name, const std::string &option, const std::string &value, const reply_callback_t &reply_callback=nullptr) |
| sentinel & | slaves (const std::string &name, const reply_callback_t &reply_callback=nullptr) |
| const std::vector< sentinel_def > & | get_sentinels (void) const |
| std::vector< sentinel_def > & | get_sentinels (void) |
cpp_redis::sentinel is the class providing sentinel configuration. It is meant to be used for sending sentinel-related commands to the remote server and receiving its replies. It is also meant to be used with cpp_redis::client and cpp_redis::subscriber for high availability (automatic failover if reconnection is enabled).
| typedef std::function<void(reply&)> cpp_redis::sentinel::reply_callback_t |
callback to be called whenever a reply has been received
| typedef std::function<void(sentinel&)> cpp_redis::sentinel::sentinel_disconnect_handler_t |
handlers called whenever disconnection occurred function takes the sentinel current instance as parameter
| cpp_redis::sentinel::sentinel | ( | void | ) |
ctor & dtor
default ctor
|
explicit |
custom ctor to specify custom tcp_client
| tcp_client | tcp client to be used for network communications |
| sentinel& cpp_redis::sentinel::add_sentinel | ( | const std::string & | host, |
| std::size_t | port, | ||
| std::uint32_t | timeout_msecs = 0 |
||
| ) |
add a sentinel definition. Required for connect() or get_master_addr_by_name() when autoconnect is enabled.
| host | sentinel host |
| port | sentinel port |
| timeout_msecs | maximum time to connect |
| void cpp_redis::sentinel::clear_sentinels | ( | void | ) |
clear all existing sentinels.
| sentinel& cpp_redis::sentinel::commit | ( | void | ) |
commit pipelined transaction that is, send to the network all commands pipelined by calling send()
| void cpp_redis::sentinel::connect | ( | const std::string & | host, |
| std::size_t | port, | ||
| const sentinel_disconnect_handler_t & | disconnect_handler = nullptr, |
||
| std::uint32_t | timeout_msecs = 0 |
||
| ) |
Connect to named sentinel
| host | host to be connected to |
| port | port to be connected to |
| timeout_msecs | maximum time to connect |
| disconnect_handler | handler to be called whenever disconnection occurs |
| void cpp_redis::sentinel::connect_sentinel | ( | const sentinel_disconnect_handler_t & | disconnect_handler = nullptr | ) |
Connect to 1st active sentinel we find. Requires add_sentinel() to be called first will use timeout set for each added sentinel independently
| disconnect_handler | handler to be called whenever disconnection occurs |
| void cpp_redis::sentinel::disconnect | ( | bool | wait_for_removal = false | ) |
disconnect from redis server
| wait_for_removal | when sets to true, disconnect blocks until the underlying TCP client has been effectively removed from the io_service and that all the underlying callbacks have completed. |
| bool cpp_redis::sentinel::get_master_addr_by_name | ( | const std::string & | name, |
| std::string & | host, | ||
| std::size_t & | port, | ||
| bool | autoconnect = true |
||
| ) |
Used to find the current redis master by asking one or more sentinels. Use high availablity. Handles connect() and disconnect() automatically when autoconnect=true This method is synchronous. No need to call sync_commit() or process a reply callback. Call add_sentinel() before using when autoconnect==true
| name | sentinel name |
| host | sentinel host |
| port | sentinel port |
| autoconnect | autoconnect we loop through and connect/disconnect as necessary to sentinels that were added using add_sentinel(). Otherwise we rely on the call to connect to a sentinel before calling this method. |
| const std::vector<sentinel_def>& cpp_redis::sentinel::get_sentinels | ( | void | ) | const |
| std::vector<sentinel_def>& cpp_redis::sentinel::get_sentinels | ( | void | ) |
| bool cpp_redis::sentinel::is_connected | ( | void | ) |
| sentinel& cpp_redis::sentinel::send | ( | const std::vector< std::string > & | sentinel_cmd, |
| const reply_callback_t & | callback = nullptr |
||
| ) |
send the given command the command is actually pipelined and only buffered, so nothing is sent to the network please call commit() to flush the buffer
| sentinel_cmd | command to be sent |
| callback | callback to be called when reply is received for this command |
| sentinel& cpp_redis::sentinel::sync_commit | ( | void | ) |
same as commit(), but synchronous will block until all pending commands have been sent and that a reply has been received for each of them and all underlying callbacks completed
|
inline |
same as sync_commit, but with a timeout will simply block until it completes or timeout expires
1.8.13