2015-04-02 22:19:57 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
2015-04-02 22:19:57 +08:00
|
|
|
|
#include <vector>
|
2015-04-07 23:31:31 +08:00
|
|
|
|
#include <utility>
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../stdlib/string.hpp"
|
2015-04-02 22:19:57 +08:00
|
|
|
|
|
|
|
|
|
namespace acl
|
|
|
|
|
{
|
|
|
|
|
|
2015-04-08 23:17:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> redis_cluster <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>йؼ<EFBFBD>Ⱥ redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
* this class is mainly used for redis_cluster command class to
|
|
|
|
|
* get some information about the nodes in redis cluster
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
class ACL_CPP_API redis_node
|
2015-04-02 22:19:57 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
2015-04-08 23:17:16 +08:00
|
|
|
|
/**
|
2015-04-19 22:15:30 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ʹ<EFBFBD>ô˹<EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> set_id <EFBFBD><EFBFBD> set_addr <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ψһ<EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>ͬʱ<EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> set_xxx <EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
redis_node(void);
|
|
|
|
|
~redis_node(void);
|
2015-04-02 22:19:57 +08:00
|
|
|
|
|
2015-04-19 22:15:30 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD><EFBFBD>еIJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ID <EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD><EFBFBD>⣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* set the node's ID
|
|
|
|
|
* @param id {const char*} <EFBFBD><EFBFBD>Ⱥ<EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ψһ<EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>
|
|
|
|
|
* the unique ID for one redis node in the reids cluster
|
|
|
|
|
* @return {redis_node&}
|
|
|
|
|
*/
|
|
|
|
|
redis_node& set_id(const char* id);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD><EFBFBD>еIJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ<EFBFBD>⣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* set the node's listening addr
|
|
|
|
|
* @param addr {const char*} <EFBFBD><EFBFBD>Ⱥ<EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ip:port
|
|
|
|
|
* the listening addr of one redis node in the reids cluster
|
|
|
|
|
* @return {redis_node&}
|
|
|
|
|
*/
|
|
|
|
|
redis_node& set_addr(const char* addr);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* set the current node's type
|
|
|
|
|
* @param type {const char*}
|
|
|
|
|
* @return {redis_node&}
|
|
|
|
|
*/
|
|
|
|
|
redis_node& set_type(const char* type);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* set if the current node is belonging to the current connection
|
|
|
|
|
* @param yesno {bool}
|
|
|
|
|
* @return {redis_node&}
|
|
|
|
|
*/
|
|
|
|
|
redis_node& set_myself(bool yesno);
|
|
|
|
|
|
2015-04-08 23:17:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* setting current slave node's master node
|
|
|
|
|
* @param master {const redis_node*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* the redis master node of the current slave in cluster
|
2015-04-19 22:15:30 +08:00
|
|
|
|
* @return {redis_node&}
|
|
|
|
|
*/
|
|
|
|
|
redis_node& set_master(const redis_node* master);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
|
|
|
|
* set the current node being in handshaking status
|
|
|
|
|
* @param yesno {bool}
|
|
|
|
|
* @return {redis_node&}
|
2015-04-08 23:17:16 +08:00
|
|
|
|
*/
|
2015-04-19 22:15:30 +08:00
|
|
|
|
redis_node& set_handshaking(bool yesno);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>㴦<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|
|
|
|
* set the node been connected in the cluster
|
|
|
|
|
* @param yesno {bool}
|
|
|
|
|
* @return {redis_node&}
|
|
|
|
|
*/
|
|
|
|
|
redis_node& set_connected(bool yesno);
|
2015-04-08 23:17:16 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>
|
|
|
|
|
* setting current node's master node when the node is slave node
|
|
|
|
|
* @param id {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ψһ<EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>
|
|
|
|
|
* the unique ID of the master node
|
2015-04-19 22:15:30 +08:00
|
|
|
|
* @return {redis_node&}
|
2015-04-08 23:17:16 +08:00
|
|
|
|
*/
|
2015-04-19 22:15:30 +08:00
|
|
|
|
redis_node& set_master_id(const char* id);
|
2015-04-08 23:17:16 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* add one slave node to the current node if it's one master node
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> false
|
|
|
|
|
* false will be returned when the slave to be added is already
|
|
|
|
|
* existing in the current master node
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
bool add_slave(redis_node* slave);
|
2015-04-08 23:17:16 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD><EFBFBD>Ψһ<EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* when the current node is a master node, this function will
|
|
|
|
|
* remove one slave node by the unique ID
|
|
|
|
|
* @param id {const char*} redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ψһ<EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>
|
|
|
|
|
* the unique ID of the redis node
|
|
|
|
|
* @return {const redis_node*} <EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD>Ĵӽ<EFBFBD><EFBFBD>㣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL
|
|
|
|
|
* the slave node according to the ID will be returned, and if
|
|
|
|
|
* not exists NULL will be returned
|
|
|
|
|
*/
|
|
|
|
|
redis_node* remove_slave(const char* id);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ձ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>дӽ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* clear all the slave nodes in the current master node
|
|
|
|
|
* @param free_all {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>Ҫͬʱ<EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* if freeing the all slave nodes memory meanwhile
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
void clear_slaves(bool free_all = false);
|
2015-04-02 22:19:57 +08:00
|
|
|
|
|
2015-04-08 23:17:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD>ϣ<EFBFBD>۷<EFBFBD>Χ
|
|
|
|
|
* add hash-slots range to the master node
|
|
|
|
|
* @param min {size_t} <EFBFBD><EFBFBD>ϣ<EFBFBD>۷<EFBFBD>Χ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼֵ
|
|
|
|
|
* the begin hash-slot of the slots range
|
|
|
|
|
* @param max {size_t} <EFBFBD><EFBFBD>ϣ<EFBFBD>۷<EFBFBD>Χ<EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* the end hash-slot of the slots range
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
void add_slot_range(size_t min, size_t max);
|
2015-04-02 22:19:57 +08:00
|
|
|
|
|
2015-04-08 23:17:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD>۷<EFBFBD>Χ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD>۷<EFBFBD>Χ
|
|
|
|
|
* @return {const std::vector<std::pair<size_t, size_t> >&}
|
|
|
|
|
*/
|
|
|
|
|
const std::vector<std::pair<size_t, size_t> >& get_slots() const;
|
|
|
|
|
|
2015-04-19 22:15:30 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* get the node's type
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
|
|
|
|
const char* get_type() const
|
|
|
|
|
{
|
|
|
|
|
return type_.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>жϵ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* check if the node belongs to the current connection
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool is_myself() const
|
|
|
|
|
{
|
|
|
|
|
return myself_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>жϵ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
|
|
|
|
* check if the node is in handshaking status
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool is_handshaking() const
|
|
|
|
|
{
|
|
|
|
|
return handshaking_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>жϵ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|
|
|
|
* check if the node is connected in the cluster
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool is_connected() const
|
|
|
|
|
{
|
|
|
|
|
return connected_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 23:17:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>øôӽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* get the current slave's master node
|
|
|
|
|
* @return {const redis_node*}
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
const redis_node* get_master() const
|
2015-04-02 22:19:57 +08:00
|
|
|
|
{
|
2015-04-07 23:31:31 +08:00
|
|
|
|
return master_;
|
2015-04-02 22:19:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 23:17:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>øôӽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ID <EFBFBD><EFBFBD>ʶ
|
|
|
|
|
* when the current node is slave, getting its master's ID
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
const char* get_master_id() const
|
2015-04-02 22:19:57 +08:00
|
|
|
|
{
|
2015-04-07 23:31:31 +08:00
|
|
|
|
return master_id_.c_str();
|
2015-04-02 22:19:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 23:17:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ø<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>дӽ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* getting all the slaves of the master
|
|
|
|
|
* @return {const std::vector<redis_node*>*}
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
const std::vector<redis_node*>* get_slaves() const
|
2015-04-02 22:19:57 +08:00
|
|
|
|
{
|
2015-04-19 22:15:30 +08:00
|
|
|
|
return &slaves_;
|
2015-04-02 22:19:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 23:17:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>жϵ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD>Ⱥ<EFBFBD>е<EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* check if the current node is a master in the redis cluster
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
bool is_master() const
|
2015-04-02 22:19:57 +08:00
|
|
|
|
{
|
2015-04-07 23:31:31 +08:00
|
|
|
|
return master_ == this;
|
2015-04-02 22:19:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 23:17:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ID <EFBFBD><EFBFBD>ʶ
|
|
|
|
|
* get the unique ID of the current node, set in constructor
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
const char* get_id() const
|
|
|
|
|
{
|
|
|
|
|
return id_.c_str();
|
|
|
|
|
}
|
2015-04-02 22:19:57 +08:00
|
|
|
|
|
2015-04-08 23:17:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
* get the listening addr of the current node, set in constructor
|
|
|
|
|
* @reutrn {const char*}
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
const char* get_addr() const
|
|
|
|
|
{
|
|
|
|
|
return addr_.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-01 10:48:41 +08:00
|
|
|
|
/**
|
2018-01-01 11:05:05 +08:00
|
|
|
|
* result of CLUSTER NODES for redis.4.x.x:
|
2018-01-01 10:48:41 +08:00
|
|
|
|
* d52ea3cb4cdf7294ac1fb61c696ae6483377bcfc 127.0.0.1:16385@116385 master - 0 1428410625374 73 connected 5461-10922
|
2018-01-01 11:05:05 +08:00
|
|
|
|
* @return return 127.0.0.1:16385@116385 for redis.4.x.x
|
2018-01-01 10:48:41 +08:00
|
|
|
|
*/
|
2018-01-01 11:05:05 +08:00
|
|
|
|
const char* get_addr_info() const
|
2018-01-01 10:48:41 +08:00
|
|
|
|
{
|
2018-01-01 11:05:05 +08:00
|
|
|
|
return addr_info_.c_str();
|
2018-01-01 10:48:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-07 23:31:31 +08:00
|
|
|
|
private:
|
|
|
|
|
string id_;
|
|
|
|
|
string addr_;
|
2018-01-01 11:05:05 +08:00
|
|
|
|
string addr_info_;
|
2015-04-19 22:15:30 +08:00
|
|
|
|
string type_;
|
|
|
|
|
bool myself_;
|
|
|
|
|
bool handshaking_;
|
|
|
|
|
bool connected_;
|
2015-04-07 23:31:31 +08:00
|
|
|
|
const redis_node* master_;
|
|
|
|
|
string master_id_;
|
2015-04-02 22:19:57 +08:00
|
|
|
|
std::vector<redis_node*> slaves_;
|
2015-04-07 23:31:31 +08:00
|
|
|
|
std::vector<std::pair<size_t, size_t> > slots_;
|
2015-04-02 22:19:57 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|