acl
3.5.3.0
|
#include <redis_client_cluster.hpp>
Public 成员函数 | |
redis_client_cluster (int max_slot=16384) | |
virtual | ~redis_client_cluster (void) |
redis_client_pool * | peek_slot (int slot) |
void | set_slot (int slot, const char *addr) |
void | set_all_slot (const char *addr, size_t max_conns, int conn_timeout=30, int rw_timeout=30) |
void | clear_slot (int slot) |
int | get_max_slot () const |
void | set_redirect_max (int max) |
int | get_redirect_max () const |
void | set_redirect_sleep (int n) |
int | get_redirect_sleep () const |
redis_client_cluster & | set_ssl_conf (sslbase_conf *ssl_conf) |
redis_client_cluster & | set_password (const char *addr, const char *pass) |
const std::map< string, string > & | get_passwords (void) const |
const char * | get_password (const char *addr) const |
redis_client * | redirect (const char *addr, size_t max_conns) |
redis_client * | peek_conn (int slot) |
const redis_result * | run (redis_command &cmd, size_t nchild, int *timeout=NULL) |
Public 成员函数 继承自 acl::connect_manager | |
connect_manager (void) | |
virtual | ~connect_manager (void) |
void | bind_thread (bool yes) |
void | init (const char *default_addr, const char *addr_list, size_t count, int conn_timeout=30, int rw_timeout=30) |
void | set (const char *addr, size_t count, int conn_timeout=30, int rw_timeout=30) |
const conn_config * | get_config (const char *addr, bool use_first=false) |
void | set_retry_inter (int n) |
void | set_idle_ttl (time_t ttl) |
void | set_check_inter (int n) |
void | remove (const char *addr) |
connect_pool * | get (const char *addr, bool exclusive=true, bool restore=false) |
virtual connect_pool * | peek (void) |
virtual connect_pool * | peek (const char *key, bool exclusive=true) |
void | lock (void) |
void | unlock (void) |
std::vector< connect_pool * > & | get_pools (void) |
size_t | check_idle (size_t step, size_t *left=NULL) |
size_t | size (void) const |
connect_pool * | get_default_pool (void) |
void | statistics (void) |
bool | start_monitor (connect_monitor *monitor) |
connect_monitor * | stop_monitor (bool graceful=true) |
void | set_pools_status (const char *addr, bool alive) |
Protected 成员函数 | |
connect_pool * | create_pool (const char *addr, size_t count, size_t idx) |
Protected 成员函数 继承自 acl::connect_manager | |
void | set_service_list (const char *addr_list, int count, int conn_timeout, int rw_timeout) |
conns_pools & | get_pools_by_id (unsigned long id) |
connect_pool * | create_pool (const conn_config &cf, size_t idx) |
void | create_pools_for (pools_t &pools) |
void | remove (pools_t &pools, const char *addr) |
void | set_status (pools_t &pools, const char *addr, bool alive) |
unsigned long | get_id (void) const |
void | get_key (const char *addr, string &key) |
void | get_addr (const char *key, string &addr) |
connect_pool * | add_pool (const char *addr) |
Protected 成员函数 继承自 acl::acl::noncopyable | |
noncopyable () | |
~noncopyable () | |
额外继承的成员函数 | |
Protected 类型 继承自 acl::connect_manager | |
typedef std::vector< connect_pool * > | pools_t |
typedef pools_t::iterator | pools_it |
typedef pools_t::const_iterator | pools_cit |
typedef std::map< unsigned long, conns_pools * > | manager_t |
typedef manager_t::iterator | manager_it |
typedef manager_t::const_iterator | manager_cit |
静态 Protected 成员函数 继承自 acl::connect_manager | |
static void | thread_oninit (void) |
static void | thread_onexit (void *ctx) |
Protected 属性 继承自 acl::connect_manager | |
bool | thread_binding_ |
string | default_addr_ |
connect_pool * | default_pool_ |
std::map< string, conn_config > | addrs_ |
manager_t | manager_ |
locker | lock_ |
int | stat_inter_ |
int | retry_inter_ |
time_t | idle_ttl_ |
int | check_inter_ |
connect_monitor * | monitor_ |
redis 客户端集群类,通过将此类对象注册入 redis 客户端命令类(redis_command), 则使所有的客户端命令自动支持集群版 redis 命令。 redis client cluster class. The class's object is set in the redis_command using redis_command::set_cluster(redis_cluster*), and all the redis client command will support the redis cluster mode.
在文件 redis_client_cluster.hpp 第 24 行定义.
acl::redis_client_cluster::redis_client_cluster | ( | int | max_slot = 16384 | ) |
构造函数; constructor
max_slot | {int} 哈希槽最大值; the max hash-slot value of keys |
|
virtual |
void acl::redis_client_cluster::clear_slot | ( | int | slot | ) |
动态清除哈希槽对应的 redis 服务地址,以便于重新计算位置, 内部有线程锁保护机制; dynamicly remove one slot and redis-server addr mapping, which is protected by thread mutex
slot | {int} 哈希槽值; hash-slot value |
|
protectedvirtual |
基类纯虚函数,用来创建连接池对象,该函数返回后由基类设置网络连接及IO 超时时间 virtual function of base class, which is used to create the connection pool
addr | {const char*} 服务器监听地址,格式:ip:port; the server addr for the connection pool, such as ip:port |
count | {size_t} 连接池的大小限制,该值没有 0 时则没有限制 the max connections in one connection pool, if it's 0 there is no limit of the connections pool. |
idx | {size_t} 该连接池对象在集合中的下标位置(从 0 开始); the index of the connection pool in pool array |
实现了 acl::connect_manager.
|
inline |
const char* acl::redis_client_cluster::get_password | ( | const char * | addr | ) | const |
获得给定地址的 redis 节点的连接密码,返回 NULL 表示未设置 get the connection password of the specified addr for one redis, NULL will be returned if password wasn't set
addr | {const char*} |
获得 redis 集群中服务节点与连接密码的对照表 get all passwords of the redis cluster
在文件 redis_client_cluster.hpp 第 166 行定义.
|
inline |
设置协议重定向次数的阀值; get redirect limit of MOVE/ASK commands in one redis redirect process
在文件 redis_client_cluster.hpp 第 108 行定义.
|
inline |
获得 set_redirect_sleep 设置的或默认的时间; get sleep time set by set_redirect_sleep function
在文件 redis_client_cluster.hpp 第 134 行定义.
redis_client* acl::redis_client_cluster::peek_conn | ( | int | slot | ) |
根据 redis 集群的槽号获得连接对象
slot | {int} redis 集群键值对应的存储槽槽号 |
redis_client_pool* acl::redis_client_cluster::peek_slot | ( | int | slot | ) |
根据哈希槽值获得对应的连接池; get one connection pool with the given slot
slot | {int} 哈希槽值; the hash-slot value of key |
redis_client* acl::redis_client_cluster::redirect | ( | const char * | addr, |
size_t | max_conns | ||
) |
重定向至目标 redis 节点
addr | {const char*} 目标 redis 服务地址 |
max_conns | {size_t} 连接池最大连接数 |
const redis_result* acl::redis_client_cluster::run | ( | redis_command & | cmd, |
size_t | nchild, | ||
int * | timeout = NULL |
||
) |
void acl::redis_client_cluster::set_all_slot | ( | const char * | addr, |
size_t | max_conns, | ||
int | conn_timeout = 30 , |
||
int | rw_timeout = 30 |
||
) |
给定 redis 集群中的一个结点,自动发现所有的哈希槽对应的结点地址 according one node of the cluster, auto find all nodes with all slots range
addr | {const char*} 集群中的一个服务结点地址,格式 ip:port on server node's addr of the cluster, addr format is "ip:port" |
max_conns | {size_t} 集群中与每个结点所建连接池的最大连接限制 the max connections limit for each connection pool |
conn_timeout | {int} 连接超时时间 set the connection timeout |
rw_timeout | {int} IO 读写超时时间 set the network io timeout |
redis_client_cluster& acl::redis_client_cluster::set_password | ( | const char * | addr, |
const char * | pass | ||
) |
设置某个 redis 服务相应的连接密码 set the password of one redis-server
addr | {const char*} 指定的某 redis 服务器地址,当该参数的值为 default 时,则指定了集群中所有 redis 服务器的缺省连接密码 the specified redis-server's addr, the default password of all redis-server will be set when the addr's value is 'default' |
pass | {const char*} 指定的 redis 服务器连接密码 the password of the specified redis-server |
void acl::redis_client_cluster::set_redirect_max | ( | int | max | ) |
设置协议重定向次数的阀值,默认值为 15; set redirect limit for MOVE/ASK, default is 15
max | {int} 重定向次数阀值,只有当该值 > 0 时才有效; the redirect times limit for MOVE/ASK commands |
void acl::redis_client_cluster::set_redirect_sleep | ( | int | n | ) |
当重定向次数 >= 2 时允许休眠的时间(毫秒),默认值为 100 毫秒,这样做的 好处是当一个 redis 服务主结点掉线后,其它从结点升级为主结点是需要 时间的(由 redis.conf 中的 cluster-node-timeout 配置项决定),所以 为了在重定向的次数范围内不报错需要等待从结点升级为主结点; if redirect happenning more than 2 in one redis command process, the process can sleep for a one avoiding redirect too fast, you can set the waiting time with microsecond here, default value is 100 microseconds; this only happends when redis-server died.
n | {int} 每次重定向时的休息时间(毫秒),默认值为 100 毫秒; microseonds to sleep when redirect times are more than 2, default is 100 ms |
void acl::redis_client_cluster::set_slot | ( | int | slot, |
const char * | addr | ||
) |
动态设置哈希槽值对应的 redis 服务地址,该函数被调用时内部有线程锁保护; dynamicly set redis-server addr with one slot, which is protected by thread mutex internal, no one will be set if the slot were beyyond the max hash-slot
slot | {int} 哈希槽值; the hash-slot |
addr | {const char*} redis 服务器地址; one redis-server addr |
redis_client_cluster& acl::redis_client_cluster::set_ssl_conf | ( | sslbase_conf * | ssl_conf | ) |
设置 SSL 通信方式下的配置句柄,内部缺省值为 NULL,如果设置了 SSL 连 接配置对象,则内部切换成 SSL 通信方式 set SSL communication with Redis-server if ssl_conf not NULL
ssl_conf | {sslbase_conf*} |