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

98 lines
1.9 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
#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
*
*/
redis_slot(size_t slot_min, size_t slot_max,
const char* ip, int port);
redis_slot(const redis_slot& node);
~redis_slot(void);
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
*/
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*>&}
*/
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*}
*/
const char* get_ip(void) const
{
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}
*/
int get_port(void) const
{
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}
*/
size_t get_slot_min(void) const
{
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}
*/
size_t get_slot_max(void) const
{
return slot_max_;
}
private:
size_t slot_min_;
size_t slot_max_;
char ip_[128];
int port_;
std::vector<redis_slot*> slaves_;
};
} // namespace acl