2015-04-07 23:31:31 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
2015-04-07 23:31:31 +08:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace acl
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class ACL_CPP_API redis_slot
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-04-12 21:37:17 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|
|
|
|
* constructor
|
|
|
|
|
* @param slot_min {size_t} <EFBFBD><EFBFBD>С<EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* the min hash-slot
|
|
|
|
|
* @param slot_max {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* the max hash-slot
|
|
|
|
|
* @param ip {const char*} <EFBFBD><EFBFBD>ǰ redis-server <EFBFBD><EFBFBD> IP <EFBFBD><EFBFBD>ַ
|
|
|
|
|
* the given redis-server's ip
|
|
|
|
|
* @param port {int} <EFBFBD><EFBFBD>ǰ redis-server <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>
|
|
|
|
|
* the listening port of the given redis-server
|
|
|
|
|
*
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
redis_slot(size_t slot_min, size_t slot_max,
|
|
|
|
|
const char* ip, int port);
|
|
|
|
|
redis_slot(const redis_slot& node);
|
|
|
|
|
|
2016-01-17 13:35:12 +08:00
|
|
|
|
~redis_slot(void);
|
2015-04-07 23:31:31 +08:00
|
|
|
|
|
2015-04-12 21:37:17 +08:00
|
|
|
|
/**
|
|
|
|
|
* <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>
|
|
|
|
|
* add a slave slot node to the current node
|
|
|
|
|
* @param node {redis_slot*} һ<EFBFBD><EFBFBD><EFBFBD>洢<EFBFBD><EFBFBD>ϣ<EFBFBD>۵Ĵӽ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* the slave slot node
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
redis_slot& add_slave(redis_slot* node);
|
|
|
|
|
|
2015-04-12 21:37:17 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD>ϣ<EFBFBD>۽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>дӽ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* get the slave nodes of the current node
|
|
|
|
|
* @return {const std::vector<redis_slot*>&}
|
|
|
|
|
*/
|
2015-04-07 23:31:31 +08:00
|
|
|
|
const std::vector<redis_slot*>& get_slaves() const
|
|
|
|
|
{
|
|
|
|
|
return slaves_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-12 21:37:17 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP <EFBFBD><EFBFBD>ַ
|
|
|
|
|
* get the ip of the current node
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
const char* get_ip(void) const
|
2015-04-07 23:31:31 +08:00
|
|
|
|
{
|
|
|
|
|
return ip_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-12 21:37:17 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ˿ں<EFBFBD>
|
|
|
|
|
* get the port of the current node
|
|
|
|
|
* @return {int}
|
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
int get_port(void) const
|
2015-04-07 23:31:31 +08:00
|
|
|
|
{
|
|
|
|
|
return port_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-12 21:37:17 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD>ϣ<EFBFBD>۽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сֵ
|
|
|
|
|
* get the min hash slot of the current node
|
|
|
|
|
* @return {size_t}
|
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
size_t get_slot_min(void) const
|
2015-04-07 23:31:31 +08:00
|
|
|
|
{
|
|
|
|
|
return slot_min_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-12 21:37:17 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><EFBFBD>ϣ<EFBFBD>۽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* get the max hash slot of the current node
|
|
|
|
|
* @return {size_t}
|
|
|
|
|
*/
|
2016-01-17 13:35:12 +08:00
|
|
|
|
size_t get_slot_max(void) const
|
2015-04-07 23:31:31 +08:00
|
|
|
|
{
|
|
|
|
|
return slot_max_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
size_t slot_min_;
|
|
|
|
|
size_t slot_max_;
|
|
|
|
|
char ip_[128];
|
|
|
|
|
int port_;
|
|
|
|
|
|
|
|
|
|
std::vector<redis_slot*> slaves_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|