acl/lib_acl_cpp/include/acl_cpp/redis/redis_cluster.hpp

315 lines
10 KiB
C++
Raw Normal View History

#pragma once
#include "acl_cpp/acl_cpp_define.hpp"
#include <vector>
#include <list>
#include <map>
#include "acl_cpp/stdlib/string.hpp"
#include "acl_cpp/redis/redis_command.hpp"
namespace acl
{
class redis_result;
class redis_node;
class redis_slot;
class ACL_CPP_API redis_cluster : virtual public redis_command
{
public:
/**
* see redis_command::redis_command()
*/
redis_cluster(void);
/**
* see redis_command::redis_command(redis_client*)
*/
redis_cluster(redis_client* conn);
/**
2016-05-22 09:10:34 +08:00
* see redis_command::redis_command(redis_client_cluster*, size_t)
*/
redis_cluster(redis_client_cluster* cluster, size_t max_conns = 0);
virtual ~redis_cluster(void);
2015-03-01 23:50:53 +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> 0 <EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* add some hash-slots, the last slot value must be < 0 indicating
* the end of the slots array
* @param first {int} <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>ۣ<EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> >= 0 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
* the first hash-slot which must be >= 0
* @param slot_list {const int[]} Ҫ<EFBFBD><EFBFBD><EFBFBD>ӵĹ<EFBFBD>ϣ<EFBFBD>۵<EFBFBD><EFBFBD>б<EFBFBD>
* the hash-slots array to be added
* @param n {size_t} the count of the hash-slots list
* @param slot_list {const std::vector<init>&} Ҫ<EFBFBD><EFBFBD><EFBFBD>ӵĹ<EFBFBD>ϣ<EFBFBD>۵<EFBFBD><EFBFBD>б<EFBFBD>
* the hash-slots list to be added
* @return {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* return true if successful
*/
bool cluster_addslots(int first, ...);
bool cluster_addslots(const int slot_list[], size_t n);
bool cluster_addslots(const std::vector<int>& slot_list);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>ۣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD> 0 <EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD>۱<EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* remove some hash-slots, the last slot value must be < 0 indicating
* the end of the slots array
* @param first {int} <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>ۣ<EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> >= 0 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
* the first hash-slot which must be >= 0
* @param slot_list {const int[]} Ҫɾ<EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD>۵<EFBFBD><EFBFBD>б<EFBFBD>
* the hash-slots array to be removed
* @param n {size_t} the count of the hash-slots list
* @param slot_list {const std::vector<init>&} Ҫɾ<EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD>۵<EFBFBD><EFBFBD>б<EFBFBD>
* the hash-slots array to be removed
* @return {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* return true if successful
*/
bool cluster_delslots(int first, ...);
bool cluster_delslots(const int slot_list[], size_t n);
bool cluster_delslots(const std::vector<int>& slot_list);
/**
* <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>
* get keys array stored in one specified hash-slot
* @param slot {size_t} <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ
* the specified hash-slot
* @param max {size_t} <EFBFBD><EFBFBD><EFBFBD>ƵĽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* limit the max results count
* @param result {std::list<acl::string>&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* stored the results
* @return {int} <EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-1 <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* >= 0 if OK, -1 if error
*/
int cluster_getkeysinslot(size_t slot, size_t max, std::list<string>& result);
/**
* <EFBFBD>ڽ<EFBFBD><EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD>Ⱥʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<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>
* let one redis node to link to the other redis node
* when buiding the redis cluster
* @param ip {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP <EFBFBD><EFBFBD>ַ
* the other redis node's ip to be linked
* @param port {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> port <EFBFBD>˿<EFBFBD>
* the other redis node's port to be linked
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if the linking is successful
*/
bool cluster_meet(const char* ip, int port);
/**
* <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><EFBFBD>
* <EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD> reset_soft
* reset one redis node's status, escaping from the other nodes
* of the redis cluster, and clearing slot-to-nodes mapping;
* same as reset_soft
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if the operation is successful
*/
bool cluster_reset();
bool cluster_reset_hard();
bool cluster_reset_soft();
/**
* <EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ǰ redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD>״̬
* set the hash-slot in importing status from the other node
* to the current node
* @param slot {size_t} <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ
* the hash-slot value
* @param src_node {const char*} <EFBFBD>ù<EFBFBD>ϣ<EFBFBD>۵<EFBFBD> redis Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* the source redis-node of the hash-slot importing from
* @return {boo} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if success for setting the slot's status
*/
bool cluster_setslot_importing(size_t slot, const char* src_node);
/**
* <EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ǰ redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǩ<EFBFBD><EFBFBD>״̬
* set the hash-slot in migrating status to the other node
* from the current node
* @param slot {size_t} <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ
* the hash-slot value
* @param src_node {const char*} <EFBFBD>ù<EFBFBD>ϣ<EFBFBD>۵<EFBFBD> redis Ǩ<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* the target redis-node of the hash-slot migrating to
* @return {boo} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if success for setting the slot's status
*/
bool cluster_setslot_migrating(size_t slot, const char* dst_node);
2015-03-01 23:50:53 +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>״̬
* set the hash-slot stable after importing or migrating
* @param slot {size_t} <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ
* the hash-slot value
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if success for setting the slot's status
*/
bool cluster_setslot_stable(size_t slot);
2015-03-01 23:50:53 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<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>ĵ<EFBFBD>
* set one hash-slot to one redis node, for more help see online doc
* @param slot {size_t} <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ
* the hash-slot to be set
* @param node {const char*} <EFBFBD><EFBFBD><EFBFBD>ոù<EFBFBD>ϣ<EFBFBD>۵<EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* the redis node to be holding the hash-slot
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if the operation is successful
*/
bool cluster_setslot_node(size_t slot, const char* node);
2015-03-01 23:50:53 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* get the count of the failure resports by one redis node
* @param node {const char*} ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> >= 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ -1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* return the failure count reporting by the specified redis node,
* return value >= 0 if successful, or -1 for error happened
*/
int cluster_count_failure_reports(const char* node);
/**
* <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><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>
* this command can only be sent to one slave node for failover
* of the master node, make the current slave to be the master
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if the operation is successful
*/
bool cluster_failover();
/**
* ǿ<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><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>
* force a slave to be the master, not handshake with it's master,
* but still need get agreement by majority of the masters in cluster
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if the operation is successful
*/
bool cluster_failover_force();
/**
* ǿ<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>
* force a slave to be the master, not handshake with it's master,
* and also no need get agreement by the other masters in cluster
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if the operation is successful
*/
bool cluster_failover_takeover();
/**
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD>Ⱥ<EFBFBD><EFBFBD>һЩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
* get running informantion about the redis cluster
* @param result {std::map<acl::string, acl::string>&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* store the result of this operation
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if this operation is successful
*/
bool cluster_info(std::map<string, string>& result);
/**
* <EFBFBD>õ<EFBFBD>ǰ redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD> nodes.conf <EFBFBD><EFBFBD>
* let the current node to save the cluster information in nodes.conf
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if this operation is successful
*/
bool cluster_saveconfig();
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>еĶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* get all the keys's count in one hash-slot
* @param slot {size_t} ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>
* the specified hash-slot
* @return {int} <EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>еĶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-1 <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*<EFBFBD><EFBFBD>return the keys's count in the hash-slot, return -1 if error
*/
int cluster_countkeysinslot(size_t slot);
/**
* <EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ǰ<EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>
* remove the specified node from the current node
* @param node {const char*} ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD><EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD>
* the speicied node to be removed
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if this operation is successful
*/
bool cluster_forget(const char* node);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD><EFBFBD>
* get the hash-slot wich the key belongs to
* @param key {const char*} <EFBFBD><EFBFBD>ֵ
* the key string
* @return {int} <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>>= 0 <EFBFBD><EFBFBD>ʾ<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>-1 <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
* return the key's hash-slot, >= 0 if successful, -1 on error
*/
int cluster_keyslot(const char* key);
/**
* <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 the specified node to be a slave node
* @param node {const char*} ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>
* the specified node
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
* if this operation is successful
*/
bool cluster_replicate(const char* node);
bool cluster_set_config_epoch(const char* epoch);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD>Ⱥ<EFBFBD>и<EFBFBD><EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķֲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* get all nodes with all slots
* @return {const std::vector<redis_slot*>*} <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> NULL <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* return all the master nodes with all hash-slots in them,
* and NULL will be returned if error happened, and the return
* value needn't be freed because it can be freed internal
*/
const std::vector<redis_slot*>* cluster_slots();
/**
* <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>
* redis_node::get_slaves <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* get all the masters of the cluster, and master's slave nodes
* can be got by redis_node::get_slaves
* @return {const std::map<string, redis_node*>*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* return NULL if error happened, the return value needn't be
* freed because it can be freed internal
*/
const std::map<string, redis_node*>* cluster_nodes();
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>дӽ<EFBFBD><EFBFBD><EFBFBD>
* get all slave nodes of the specified master node
* @return node {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <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>
* one of the master node, NULL if error, and the return value
* needn't be freed because it can be freed internal
*/
const std::vector<redis_node*>* cluster_slaves(const char* node);
2015-03-01 23:50:53 +08:00
private:
std::vector<redis_slot*> slots_;
redis_slot* get_slot_master(const redis_result* rr);
redis_slot* get_slot(const redis_result* rr,
size_t slot_max, size_t slot_min);
void free_slots();
private:
std::map<string, redis_node*> masters_;
redis_node* get_node(string& line);
void add_slot_range(redis_node* node, char* slots);
void free_masters();
2015-04-19 22:15:30 +08:00
redis_node* get_slave(const std::vector<string>& tokens);
private:
std::vector<redis_node*> slaves_;
void free_slaves();
};
} // namespace acl