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-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_node.hpp"
|
|
|
|
|
#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-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>
|
|
|
|
|
* add some hash-slots, the last slot value must be < 0
|
|
|
|
|
* @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
|
|
|
|
|
* @return {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
* return true if success
|
2015-02-27 13:33:00 +08:00
|
|
|
|
*/
|
2015-04-02 22:19:57 +08:00
|
|
|
|
bool addslots(int first, ...);
|
|
|
|
|
bool addslots(const int slot_list[], size_t n);
|
|
|
|
|
bool addslots(const std::vector<int>& slot_list);
|
2015-02-27 13:33:00 +08:00
|
|
|
|
|
2015-04-02 22:19:57 +08:00
|
|
|
|
bool delslots(int first, ...);
|
|
|
|
|
bool delslots(const int slot_list[], size_t n);
|
|
|
|
|
bool delslots(const std::vector<int>& slot_list);
|
2015-03-01 23:50:53 +08:00
|
|
|
|
|
2015-04-02 22:19:57 +08:00
|
|
|
|
int getkeysinslot(size_t slot, size_t max, std::list<string>& result);
|
2015-03-01 23:50:53 +08:00
|
|
|
|
|
2015-04-02 22:19:57 +08:00
|
|
|
|
bool meet(const char* ip, int port);
|
|
|
|
|
bool reset();
|
|
|
|
|
bool reset_hard();
|
|
|
|
|
bool reset_soft();
|
2015-03-01 23:50:53 +08:00
|
|
|
|
|
2015-04-02 22:19:57 +08:00
|
|
|
|
bool setslot_importing(size_t slot, const char* src_node);
|
|
|
|
|
bool setslot_migrating(size_t slot, const char* dst_node);
|
|
|
|
|
bool setslot_stable(size_t slot);
|
|
|
|
|
bool setslot_node(size_t slot, const char* node);
|
|
|
|
|
|
|
|
|
|
int count_failure_reports(const char* node);
|
|
|
|
|
|
|
|
|
|
bool failover();
|
|
|
|
|
bool failover_force();
|
|
|
|
|
bool failover_takeover();
|
|
|
|
|
|
|
|
|
|
bool info(string& result);
|
|
|
|
|
bool nodes(string& result);
|
|
|
|
|
bool saveconfig();
|
|
|
|
|
bool slaves(const char* node, std::vector<string>& result);
|
|
|
|
|
int countkeysinslot(size_t slot);
|
|
|
|
|
bool forget(const char* node);
|
|
|
|
|
int keyslot(const char* key);
|
|
|
|
|
bool replicate(const char* node);
|
|
|
|
|
bool set_config_epoch(const char* epoch);
|
|
|
|
|
const std::vector<redis_node*>* slots();
|
2015-03-01 23:50:53 +08:00
|
|
|
|
|
2015-02-14 01:01:29 +08:00
|
|
|
|
private:
|
2015-04-02 22:19:57 +08:00
|
|
|
|
std::vector<redis_node*> nodes_;
|
|
|
|
|
|
|
|
|
|
redis_node* get_master_node(const redis_result* rr);
|
|
|
|
|
redis_node* create_node(const redis_result* rr,
|
|
|
|
|
size_t slot_max, size_t slot_min);
|
|
|
|
|
void free_nodes();
|
2015-02-14 01:01:29 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|