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>
|
|
|
|
|
#include "acl_cpp/stdlib/string.hpp"
|
2015-02-14 01:01:29 +08:00
|
|
|
|
#include "acl_cpp/connpool/connect_manager.hpp"
|
|
|
|
|
|
|
|
|
|
namespace acl
|
|
|
|
|
{
|
|
|
|
|
|
2015-02-27 13:33:00 +08:00
|
|
|
|
class redis_pool;
|
|
|
|
|
|
2015-02-14 01:01:29 +08:00
|
|
|
|
class ACL_CPP_API redis_cluster : public connect_manager
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|
|
|
|
* @param conn_timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʱʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>)
|
|
|
|
|
* @param rw_timeout {int}<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IO <EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>)
|
2015-02-27 13:33:00 +08:00
|
|
|
|
* @param max_slot {int} <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
2015-02-14 01:01:29 +08:00
|
|
|
|
*/
|
2015-02-27 13:33:00 +08:00
|
|
|
|
redis_cluster(int conn_timeout, int rw_timeout, int max_slot = 16384);
|
2015-02-14 01:01:29 +08:00
|
|
|
|
virtual ~redis_cluster();
|
|
|
|
|
|
2015-02-27 13:33:00 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ݹ<EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>
|
|
|
|
|
* @param slot {int} <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* @return {redis_pool*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ĺ<EFBFBD>ϣ<EFBFBD>۲<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL
|
|
|
|
|
*/
|
|
|
|
|
redis_pool* peek_slot(int slot);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD> redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
* @param slot {int} <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* @param addr {const char*} redis <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
*/
|
|
|
|
|
void set_slot(int slot, const char* addr);
|
|
|
|
|
|
2015-03-01 23:50:53 +08:00
|
|
|
|
/**
|
|
|
|
|
* <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><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param slot {int} <EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD>ֵ
|
|
|
|
|
*/
|
|
|
|
|
void clear_slot(int slot);
|
|
|
|
|
|
2015-02-27 13:33:00 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
* @return {int}
|
|
|
|
|
*/
|
|
|
|
|
int get_max_slot() const
|
|
|
|
|
{
|
|
|
|
|
return max_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>ֵ<EFBFBD><EFBFBD>Ĭ<EFBFBD><EFBFBD>ֵΪ 15
|
|
|
|
|
* @param max {int} <EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ֻ<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>ֵ > 0 ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
|
|
|
|
|
*/
|
|
|
|
|
void set_redirect_max(int max);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>ֵ
|
|
|
|
|
* @return {int}
|
|
|
|
|
*/
|
|
|
|
|
int get_redirect_max() const
|
|
|
|
|
{
|
|
|
|
|
return redirect_max_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FBD>Χ<EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ȴ<EFBFBD><EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param n {int} ÿ<EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>)<EFBFBD><EFBFBD>Ĭ<EFBFBD><EFBFBD>ֵΪ 1 <EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void set_redirect_sleep(int n);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> set_redirect_sleep <EFBFBD><EFBFBD><EFBFBD>õĻ<EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD>ʱ<EFBFBD><EFBFBD>
|
|
|
|
|
* @return {int} <EFBFBD><EFBFBD>λΪ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
int get_redirect_sleep() const
|
|
|
|
|
{
|
|
|
|
|
return redirect_sleep_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-14 01:01:29 +08:00
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ി<EFBFBD>麯<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳض<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param addr {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ip:port
|
|
|
|
|
* @param count {int} <EFBFBD><EFBFBD><EFBFBD>ӳصĴ<EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param idx {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳض<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>±<EFBFBD>λ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD> 0 <EFBFBD><EFBFBD>ʼ)
|
|
|
|
|
*/
|
|
|
|
|
virtual acl::connect_pool* create_pool(const char* addr,
|
|
|
|
|
int count, size_t idx);
|
|
|
|
|
private:
|
|
|
|
|
int conn_timeout_;
|
|
|
|
|
int rw_timeout_;
|
2015-02-27 13:33:00 +08:00
|
|
|
|
int max_slot_;
|
|
|
|
|
const char** slot_addrs_;
|
|
|
|
|
std::vector<char*> addrs_;
|
2015-03-01 23:50:53 +08:00
|
|
|
|
int redirect_max_;
|
|
|
|
|
int redirect_sleep_;
|
2015-02-14 01:01:29 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|