| cpp_redis 4.0.0 cpp_redis is a C++11 Asynchronous Multi-Platform Lightweight Redis Client, with support for synchronous operations and pipelining.

Classes | Public Types | Public Member Functions | List of all members
cpp_redis::sentinel Class Reference

`#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)

## Detailed Description

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).

## Member Typedef Documentation

## ◆ reply_callback_t

typedef std::function<void(reply&)> cpp_redis::sentinel::reply_callback_t

callback to be called whenever a reply has been received

## ◆ sentinel_disconnect_handler_t

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

## Constructor & Destructor Documentation

## ◆ sentinel() [1/2]

cpp_redis::sentinel::sentinel | ( | void |  | ) |

ctor & dtor

default ctor

## ◆ sentinel() [2/2]

cpp_redis::sentinel::sentinel | ( | const std::shared_ptr< network::tcp_client_iface > & | tcp_client | ) |
| explicit

custom ctor to specify custom tcp_client

Parameters

  tcp_client | tcp client to be used for network communications

## Member Function Documentation

## ◆ add_sentinel()

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.

Parameters

  host | sentinel host
  port | sentinel port
  timeout_msecs | maximum time to connect

Returns
  current instance

## ◆ clear_sentinels()

void cpp_redis::sentinel::clear_sentinels | ( | void |  | ) |

clear all existing sentinels.

## ◆ commit()

sentinel& cpp_redis::sentinel::commit | ( | void |  | ) |

commit pipelined transaction that is, send to the network all commands pipelined by calling send()

Returns
  current instance

## ◆ connect()

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

Parameters

  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

## ◆ connect_sentinel()

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

Parameters

  disconnect_handler | handler to be called whenever disconnection occurs

## ◆ disconnect()

void cpp_redis::sentinel::disconnect | ( | bool | wait_for_removal = `false` | ) |

disconnect from redis server

Parameters

  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.

## ◆ get_master_addr_by_name()

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

Parameters

  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.

Returns
  true if a master was found and fills in host and port output parameters, false otherwise

## ◆ get_sentinels() [1/2]

const std::vector<sentinel_def>& cpp_redis::sentinel::get_sentinels | ( | void |  | ) | const

Returns
  sentinels

## ◆ get_sentinels() [2/2]

std::vector<sentinel_def>& cpp_redis::sentinel::get_sentinels | ( | void |  | ) |

Returns
  sentinels (non-const version)

## ◆ is_connected()

bool cpp_redis::sentinel::is_connected | ( | void |  | ) |

Returns
  whether we are connected to the redis server or not

## ◆ send()

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

Parameters

  sentinel_cmd | command to be sent
  callback | callback to be called when reply is received for this command

Returns
  current instance

## ◆ sync_commit() [1/2]

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

Returns
  current instance

## ◆ sync_commit() [2/2]

template<class Rep , class Period >

sentinel& cpp_redis::sentinel::sync_commit | ( | const std::chrono::duration< Rep, Period > & | timeout | ) |
| inline

same as sync_commit, but with a timeout will simply block until it completes or timeout expires

Returns
  current instance

The documentation for this class was generated from the following file:

- includes/cpp_redis/core/sentinel.hpp