2015-02-14 01:01:29 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
#include "acl_cpp/acl_cpp_define.hpp"
|
2015-02-27 13:33:00 +08:00
|
|
|
|
#include <vector>
|
2015-04-02 22:19:57 +08:00
|
|
|
|
#include <list>
|
2015-04-07 23:31:31 +08:00
|
|
|
|
#include <map>
|
2015-02-27 13:33:00 +08:00
|
|
|
|
#include "acl_cpp/stdlib/string.hpp"
|
2015-04-02 22:19:57 +08:00
|
|
|
|
#include "acl_cpp/redis/redis_command.hpp"
|
2015-02-14 01:01:29 +08:00
|
|
|
|
|
|
|
|
|
namespace acl
|
|
|
|
|
{
|
|
|
|
|
|
2015-04-02 22:19:57 +08:00
|
|
|
|
class redis_result;
|
2015-04-07 23:31:31 +08:00
|
|
|
|
class redis_node;
|
|
|
|
|
class redis_slot;
|
2015-02-27 13:33:00 +08:00
|
|
|
|
|
2015-04-02 22:19:57 +08:00
|
|
|
|
class ACL_CPP_API redis_cluster : virtual public redis_command
|
2015-02-14 01:01:29 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
2015-04-02 22:19:57 +08:00
|
|
|
|
* see redis_command::redis_command()
|
2015-02-14 01:01:29 +08:00
|
|
|
|
*/
|
2015-04-02 22:19:57 +08:00
|
|
|
|
redis_cluster();
|
2015-02-14 01:01:29 +08:00
|
|
|
|
|
2015-02-27 13:33:00 +08:00
|
|
|
|
/**
|
2015-04-02 22:19:57 +08:00
|
|
|
|
* see redis_command::redis_command(redis_client*)
|
2015-02-27 13:33:00 +08:00
|
|
|
|
*/
|
2015-04-02 22:19:57 +08:00
|
|
|
|
redis_cluster(redis_client* conn);
|
2015-02-27 13:33:00 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2015-04-02 22:19:57 +08:00
|
|
|
|
* see redis_command::redis_command(redis_client_cluster*<EFBFBD><EFBFBD> size_t)
|
2015-02-27 13:33:00 +08:00
|
|
|
|
*/
|
2015-04-02 22:19:57 +08:00
|
|
|
|
redis_cluster(redis_client_cluster* cluster, size_t max_conns);
|
2015-02-27 13:33:00 +08:00
|
|
|
|
|
2015-04-02 22:19:57 +08:00
|
|
|
|
virtual ~redis_cluster();
|
2015-03-01 23:50:53 +08:00
|
|
|
|
|
2015-02-27 13:33:00 +08:00
|
|
|
|
/**
|
2015-04-02 22:19:57 +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>
|
2015-04-07 23:31:31 +08:00
|
|
|
|
* add some hash-slots, the last slot value must be < 0 indicating
|
|
|
|
|
* the end of the slots array
|
2015-04-02 22:19:57 +08:00
|
|
|
|
* @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
|
2015-04-07 23:31:31 +08:00
|
|
|
|
* @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
|
2015-04-02 22:19:57 +08:00
|
|
|
|
* @return {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2015-04-07 23:31:31 +08:00
|
|
|
|
* return true if successful
|
2015-02-27 13:33:00 +08:00
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
bool cluster_addslots(int first, ...);
|
|
|
|
|
bool cluster_addslots(const int slot_list[], size_t n);
|
|
|
|
|
bool cluster_addslots(const std::vector<int>& slot_list);
|
2015-02-27 13:33:00 +08:00
|
|
|
|
|
2015-04-07 23:31:31 +08:00
|
|
|
|
/**
|
|
|
|
|
* <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
|
|
|
|
|
2015-04-07 23:31:31 +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
|
|
|
|
|
2015-04-26 00:11:10 +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>
|
2015-04-07 23:31:31 +08:00
|
|
|
|
* <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
|
|
|
|
|
2015-04-07 23:31:31 +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);
|
2015-04-02 22:19:57 +08:00
|
|
|
|
|
2015-04-07 23:31:31 +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><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><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();
|
2015-04-02 22:19:57 +08:00
|
|
|
|
|
2015-04-07 23:31:31 +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><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();
|
2015-04-02 22:19:57 +08:00
|
|
|
|
|
2015-04-07 23:31:31 +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>
|
|
|
|
|
* 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
|
|
|
|
|
2015-02-14 01:01:29 +08:00
|
|
|
|
private:
|
2015-04-07 23:31:31 +08:00
|
|
|
|
std::vector<redis_slot*> slots_;
|
2015-04-02 22:19:57 +08:00
|
|
|
|
|
2015-04-07 23:31:31 +08:00
|
|
|
|
redis_slot* get_slot_master(const redis_result* rr);
|
|
|
|
|
redis_slot* get_slot(const redis_result* rr,
|
2015-04-02 22:19:57 +08:00
|
|
|
|
size_t slot_max, size_t slot_min);
|
2015-04-07 23:31:31 +08:00
|
|
|
|
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);
|
2015-04-07 23:31:31 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::vector<redis_node*> slaves_;
|
|
|
|
|
void free_slaves();
|
2015-02-14 01:01:29 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|