mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 10:57:34 +08:00
add some comments for redis module
This commit is contained in:
parent
d6933c5694
commit
cd4802771d
@ -1,6 +1,9 @@
|
||||
修改历史列表:
|
||||
|
||||
------------------------------------------------------------------------
|
||||
300) 2015.4.12
|
||||
300.1) comment: 完善了 redis 模块的英文注释
|
||||
|
||||
299) 2015.4.8
|
||||
299.1) comment: 给 redis 模块增加了一些注释
|
||||
|
||||
|
@ -16,9 +16,13 @@ class ACL_CPP_API redis_client_pool : public connect_pool
|
||||
public:
|
||||
/**
|
||||
* 构造函数
|
||||
* constructor
|
||||
* @param addr {const char*} 服务端地址,格式:ip:port
|
||||
* the redis-server's listening address, format: ip:port
|
||||
* @param count {int} 连接池的最大连接数限制
|
||||
* the max connections for each connection pool
|
||||
* @param idx {size_t} 该连接池对象在集合中的下标位置(从 0 开始)
|
||||
* the subscript of the connection pool in the connection cluster
|
||||
*/
|
||||
redis_client_pool(const char* addr, int count, size_t idx = 0);
|
||||
|
||||
@ -26,8 +30,11 @@ public:
|
||||
|
||||
/**
|
||||
* 设置网络连接超时时间及网络 IO 读写超时时间(秒)
|
||||
* set the connect and read/write timeout in seconds
|
||||
* @param conn_timeout {int} 连接超时时间
|
||||
* the timeout to connect in seconds
|
||||
* @param rw_timeout {int} 网络 IO 读写超时时间(秒)
|
||||
* the timeout to read/write in seconds
|
||||
* @return {redis_client_pool&}
|
||||
*/
|
||||
redis_client_pool& set_timeout(int conn_timeout, int rw_timeout);
|
||||
@ -35,6 +42,7 @@ public:
|
||||
protected:
|
||||
/**
|
||||
* 基类纯虚函数: 调用此函数用来创建一个新的连接
|
||||
* virtual function in class connect_pool to create a new connection
|
||||
* @return {connect_client*}
|
||||
*/
|
||||
virtual connect_client* create_connect();
|
||||
|
@ -149,8 +149,9 @@ public:
|
||||
|
||||
/**
|
||||
* 获得当前结果结点存储的对象的个数, 该方法可以获得结果为下面两个方法
|
||||
* (get_child/get_value) 所需要的数组元素的个数;
|
||||
* get number of result objects, just for functions get_child/get_value
|
||||
* (result_child/result_value) 所需要的数组元素的个数;
|
||||
* get number of result objects, just for functions
|
||||
* result_child/result_value
|
||||
* @return {size_t} 返回值与存储类型的对应关系如下:
|
||||
* the relation between return value and result type, as below:
|
||||
* REDIS_RESULT_ERROR: 1
|
||||
@ -227,13 +228,20 @@ public:
|
||||
/**
|
||||
* 当从 redis-server 获得的数据是一组字符串类型的结果集时,可以调用
|
||||
* 本函数获得某个指定下标位置的数据;
|
||||
* when the reply from redis-serveer are strings array, this
|
||||
* function can be used to get the string specified by a subscript
|
||||
* @param i {size_t} 下标(从 0 开始)
|
||||
* the subscript of strings array
|
||||
* @param len {size_t*} 若该指针非空,则存储所返回结果的长度(仅当该
|
||||
* 方法返回非空指针时有效)
|
||||
* if len not a NULL pointer, it will store the length of string
|
||||
* specified by the subscript
|
||||
* @return {const char*} 返回对应下标的值,当返回 NULL 时表示该下标没
|
||||
* 有值,为了保证使用上的安全性,返回的数据总能保证最后是以 \0 结尾,
|
||||
* 在计算数据长度时不包含该结尾符,但为了兼容二进制情形,调用者还是
|
||||
* 应该通过返回的 len 存放的长度值来获得数据的真实长度
|
||||
* the string will be returned associate with the subscript, if there
|
||||
* are nothing with the subscript, NULL will be returned
|
||||
*/
|
||||
const char* result_value(size_t i, size_t* len = NULL) const;
|
||||
|
||||
@ -241,14 +249,24 @@ public:
|
||||
/**
|
||||
* 设置是否对请求数据进行分片处理,如果为 true 则内部在组装请求协议的时候不会
|
||||
* 将所有数据块重新组装成一个连续的大数据块
|
||||
* just for request package, setting flag for sending data with
|
||||
* multi data chunks; this is useful when the request data is large
|
||||
* @param on {bool} 内部默认值为 false
|
||||
* if true the request data will not be combined one package,
|
||||
* internal default is false
|
||||
*/
|
||||
void set_slice_request(bool on);
|
||||
|
||||
/**
|
||||
* 设置是否对响应数据进行分片处理,如果为 true 则当服务器的返回数据比较大时则
|
||||
* 将数据进行分片,分成一些不连续的数据块
|
||||
* just for response package, settint flag for receiving data
|
||||
* if split the large response data into multi little chunks
|
||||
* @param on {bool} 内部默认值为 false
|
||||
* if true the response data will be splitted into multi little
|
||||
* data, which is useful for large reponse data for avoiding
|
||||
* malloc large continuously memory from system.
|
||||
* internal default is false
|
||||
*/
|
||||
void set_slice_respond(bool on);
|
||||
|
||||
|
@ -12,7 +12,8 @@ class redis_client;
|
||||
class redis_result;
|
||||
|
||||
/**
|
||||
* redis Hahs(哈希表) 类,本类的实现的主要命令:
|
||||
* redis Hash(哈希表) 类,本类的实现的主要命令:
|
||||
* redis Hash class, include commands as below:
|
||||
* HDEL/HEXISTS/HGET/HGETALL/HINCRBY/HINCRBYFLOAT/HKEYS/HLEN/HMGET/HMSET
|
||||
* HSET/HSETNX/HVALS/HSCAN
|
||||
*/
|
||||
@ -40,8 +41,12 @@ public:
|
||||
|
||||
/**
|
||||
* 将多个"域-值"对添加至 KEY 对应的哈希表中
|
||||
* HMSET: set the key's multiple fileds in redis-server
|
||||
* @param key {const char*} 哈希表 key 值
|
||||
* the hash key for Hash class
|
||||
* @param attrs {const std::map<acl::string, ...>&} the fileds in map
|
||||
* @return {bool} 添加是否成功
|
||||
* if successful for HMSET command
|
||||
*/
|
||||
bool hmset(const char* key, const std::map<string, string>& attrs);
|
||||
bool hmset(const char* key, const std::map<string, const char*>& attrs);
|
||||
@ -50,20 +55,46 @@ public:
|
||||
|
||||
/**
|
||||
* 根据 KEY 值将多个"域-值"对从哈希表中取出
|
||||
* get the values associated with the specified fields
|
||||
* in the hash stored at key
|
||||
* @param key {const char*} 哈希表 key 值
|
||||
* the hash key
|
||||
* @param names 对应 key 的域值对
|
||||
* @param result {std::vector<string>*} 当该对象指针非空时存储查询结果;
|
||||
* 如果该参数为 NULL 时,则可以通过基类 get_
|
||||
* the given hash fileds
|
||||
* @param result {std::vector<acl::string>*} 当该对象指针非空时存储查询结果;
|
||||
* 如果该参数为 NULL 时,则可以通过基类 result_/get_ 获得数据
|
||||
* store the result of the given hash files if not NULL.
|
||||
* If NULL, the base class's method like result_/get can be used
|
||||
* to get the values
|
||||
* @return {bool} 操作是否成功,操作成功后可以通过以下任一种方式获得数据:
|
||||
* 1、基类方法 get_value 获得指定下标的元素数据
|
||||
* 2、基类方法 get_child 获得指定下标的元素对象(redis_result),然后再通过
|
||||
* if successul, one of below ways can be used to get the result:
|
||||
*
|
||||
* 1、在调用方法中传入非空的存储结果对象的地址
|
||||
* input the no-NULL result parameter when call hmget, when
|
||||
* success, the result will store the values of the given fileds
|
||||
*
|
||||
* 2、基类方法 result_value 获得指定下标的元素数据
|
||||
* call redis_command::result_value with the specified subscript
|
||||
*
|
||||
* 3、基类方法 result_child 获得指定下标的元素对象(redis_result),然后再通过
|
||||
* redis_result::argv_to_string 方法获得元素数据
|
||||
* 3、基类方法 get_result 方法取得总结果集对象 redis_result,然后再通过
|
||||
* call redis_command::result_child with specified subscript to
|
||||
* get redis_result object, then call redis_result::argv_to_string
|
||||
* with above result to get the values of the give fileds
|
||||
*
|
||||
* 4、基类方法 get_result 方法取得总结果集对象 redis_result,然后再通过
|
||||
* redis_result::get_child 获得一个元素对象,然后再通过方式 2 中指定
|
||||
* 的方法获得该元素的数据
|
||||
* 4、基类方法 get_children 获得结果元素数组对象,再通过 redis_result 中
|
||||
* call redis_command::get_result with the specified subscript to
|
||||
* get redis_result object, and use redis_result::get_child to
|
||||
* get one result object, then call redis_result::argv_to_string
|
||||
* to get the value of one filed.
|
||||
*
|
||||
* 5、基类方法 get_children 获得结果元素数组对象,再通过 redis_result 中
|
||||
* 的方法 argv_to_string 从每一个元素对象中获得元素数据
|
||||
* 5、在调用方法中传入非空的存储结果对象的地址
|
||||
* use redis_command::get_children to get the redis_result array,
|
||||
* then use redis_result::argv_to_string to get every value of
|
||||
* the given fileds
|
||||
*/
|
||||
bool hmget(const char* key, const std::vector<string>& names,
|
||||
std::vector<string>* result = NULL);
|
||||
@ -79,13 +110,21 @@ public:
|
||||
|
||||
/**
|
||||
* 设置 key 对象中某个域字段的值
|
||||
* set one field's value in the hash stored at key.
|
||||
* @param key {const char*} key 键值
|
||||
* the hash key
|
||||
* @param name {const char*} key 对象的域名称
|
||||
* the filed name of the hash key
|
||||
* @param value {const char*} key 对象的域值
|
||||
* the filed value of the hash key
|
||||
* @return {int} 返回值含义:
|
||||
* 1 -- 表示新添加的域字段添加成功
|
||||
* 0 -- 表示更新已经存在的域字段成功
|
||||
* -1 -- 表示出错或该 key 对象非哈希对象或从结点禁止修改
|
||||
* return int value as below:
|
||||
* 1 -- this is a new filed and set ok
|
||||
* 0 -- thie is a old filed and set ok
|
||||
* -1 -- error happend or the key is not a Hash type
|
||||
*/
|
||||
int hset(const char* key, const char* name, const char* value);
|
||||
int hset(const char* key, const char* name,
|
||||
@ -95,13 +134,23 @@ public:
|
||||
|
||||
/**
|
||||
* 当且仅当 key 对象中的某个域字段不存在时才更新该域字段值
|
||||
* set one new field of one key in hash only when the filed isn't
|
||||
* existing.
|
||||
* @param key {const char*} key 键值
|
||||
* the hash key
|
||||
* @param name {const char*} key 对象的域名称
|
||||
* the field name
|
||||
* @param value {const char*} key 对象的域值
|
||||
* the field value
|
||||
* @return {int} 返回值含义:
|
||||
* 1 -- 表示新添加的域字段添加成功
|
||||
* 0 -- 该域字段存在且未对其进行更新
|
||||
* -1 -- 表示出错或该 key 对象非哈希对象或从结点禁止修改
|
||||
*
|
||||
* return int value as below:
|
||||
* 1 -- this is a new filed and set ok
|
||||
* 0 -- thie is a old filed and not set
|
||||
* -1 -- error happend or the key is not a Hash type
|
||||
*/
|
||||
int hsetnx(const char* key, const char* name, const char* value);
|
||||
int hsetnx(const char* key, const char* name,
|
||||
@ -111,13 +160,19 @@ public:
|
||||
|
||||
/**
|
||||
* 从 redis 哈希表中获取某个 key 对象的某个域的值
|
||||
* get the value assosiated with field in the hash stored at key
|
||||
* @param key {const char*} key 键值
|
||||
* the hash key
|
||||
* @param name {const char*} key 对象的域字段名称
|
||||
* @param result {string&} 存储查询结果值(内部对该 string 进行内容追加)
|
||||
* the field's name
|
||||
* @param result {acl::string&} 存储查询结果值(内部对该 string 进行内容追加)
|
||||
* store the value result of the given field
|
||||
* @return {bool} 返回值含义:
|
||||
* true -- 操作成功,当该域不存在时也返回成功,需要检查 result 内容是否变化,
|
||||
* 比如可以通过检查 result.length() 的变化来表明是否查询到结果
|
||||
* false -- 操作失败或该 key 对象非哈希对象
|
||||
* true -- 成功获得对象的域字段值
|
||||
* get the value associated with field
|
||||
* false -- 域字段不存在或操作失败或该 key 对象非哈希对象
|
||||
* the field not exists, or error happened,
|
||||
* or the key isn't a hash key
|
||||
*/
|
||||
bool hget(const char* key, const char* name, string& result);
|
||||
bool hget(const char* key, const char* name,
|
||||
@ -125,12 +180,18 @@ public:
|
||||
|
||||
/**
|
||||
* 从 redis 哈希表中获取某个 key 对象的所有域字段的值
|
||||
* get all the fields and values in hash stored at key
|
||||
* @param key {const char*} key 键值
|
||||
* the hash key
|
||||
* @param result {std::map<string, string>&} 存储域字段名-值查询结果集
|
||||
* store the result of all the fileds and values
|
||||
* @return {bool} 操作是否成功,含义:
|
||||
* if ok, show below:
|
||||
* true -- 操作成功,当该域不存在时也返回成功,需要检查 result 内容是否变化,
|
||||
* 比如可以通过检查 result.size() 的变化来表明是否查询到结果
|
||||
* successful if the key is a hash key or the key not exists
|
||||
* false -- 操作失败或该 key 对象非哈希对象
|
||||
* error happened or the key isn't a hash key
|
||||
*/
|
||||
bool hgetall(const char* key, std::map<string, string>& result);
|
||||
bool hgetall(const char* key, std::vector<string>& names,
|
||||
@ -140,9 +201,15 @@ public:
|
||||
|
||||
/**
|
||||
* 从 redis 哈希表中删除某个 key 对象的某些域字段
|
||||
* remove one or more fields from hash stored at key
|
||||
* @param key {const char*} key 键值
|
||||
* the hash key
|
||||
* @param first_name {const char*} 第一个域字段名,最后一个字段必须是 NULL
|
||||
* the first field of the fields list, the last field must be NULL
|
||||
* indicating the end of vary parameters
|
||||
* @return {int} 成功删除的域字段个数,返回 -1 表示出错或该 key 对象非哈希对象
|
||||
* return the number of fields be removed successfully, or -1 when
|
||||
* error happened or operating on a no hash key
|
||||
*/
|
||||
int hdel(const char* key, const char* first_name, ...);
|
||||
int hdel(const char* key, const char* names[], size_t argc);
|
||||
@ -153,69 +220,109 @@ public:
|
||||
|
||||
/**
|
||||
* 当某个 key 对象中的某个域字段为整数时,对其进行加减操作
|
||||
* inc(+n) or dec(-n) on a integer filed in hash stored at key
|
||||
* @param key {const char*} key 键值
|
||||
* the hash key
|
||||
* @param name {const char*} key 对象的域字段名称
|
||||
* the filed name of integer type
|
||||
* @param inc {long long int} 增加的值,可以为负值
|
||||
* the integer value to be inc or dec on the field's value
|
||||
* @param result {long long int*} 非 NULL 时存储结果值
|
||||
* store the result if non-NULL
|
||||
* @return {bool} 操作是否成功,当返回 false 时表明出错或该 key 对象非哈希
|
||||
* 对象或该域字段非整数类型
|
||||
* if successful: false when error, not a hash, or the field isn't
|
||||
* integer type
|
||||
*/
|
||||
bool hincrby(const char* key, const char* name,
|
||||
long long int inc, long long int* result = NULL);
|
||||
|
||||
/**
|
||||
* 当某个 key 对象中的某个域字段为浮点数时,对其进行加减操作
|
||||
* inc(+n) or dec(-n) on a float filed in hash stored at key
|
||||
* @param key {const char*} key 键值
|
||||
* the hash key
|
||||
* @param name {const char*} key 对象的域字段名称
|
||||
* the filed name of float type
|
||||
* @param inc {double} 增加的值,可以为负值
|
||||
* the float value to be inc or dec on the field's value
|
||||
* @param result {double*} 非 NULL 时存储结果值
|
||||
* store the result if non-NULL
|
||||
* @return {bool} 操作是否成功,当返回 false 时表明出错或该 key 对象非哈希
|
||||
* 对象或该域字段非浮点数类型
|
||||
* if successful: false when error, not a hash, or the field isn't
|
||||
* float type
|
||||
*/
|
||||
bool hincrbyfloat(const char* key, const char* name,
|
||||
double inc, double* result = NULL);
|
||||
|
||||
/**
|
||||
* 返回 key 对象中所有域字段名称
|
||||
* get all the fields in hash stored at key
|
||||
* @param key {const char*} key 键值
|
||||
* the hash key
|
||||
* @param names {std::vector<string>&} 存储该 key 对象所有域字段名称
|
||||
* store all the names of all fileds
|
||||
* @return {bool} 操作是否成功,返回 false 表明出错或该 key 对象非哈希对象
|
||||
* return true on success, false if error happened or the
|
||||
* key wasn't a hash key
|
||||
*/
|
||||
bool hkeys(const char* key, std::vector<string>& names);
|
||||
|
||||
/**
|
||||
* 检查 key 对象中某个域字段是否存在
|
||||
* check if the field exists in hash stored at key
|
||||
* @param key {const char*} key 键值
|
||||
* the hash key
|
||||
* @param name {const char*} key 对象的域字段名称
|
||||
* the filed's name of the key
|
||||
* @return {bool} 操作是否成功,返回 false 表明出错或该 key 对象非哈希对象
|
||||
* 或该域字段不存在
|
||||
* return true on success, false if error happened or the
|
||||
* key wasn't a hash key
|
||||
*/
|
||||
bool hexists(const char* key, const char* name);
|
||||
bool hexists(const char* key, const char* name, size_t name_len);
|
||||
|
||||
/**
|
||||
* 获得某个 key 对象中所有域字段的数量
|
||||
* get the count of fields in hash stored at key
|
||||
* @param key {const char*} key 键值
|
||||
* the hash key
|
||||
* @return {int} 返回值含义:
|
||||
* return int value as below:
|
||||
* -1 -- 出错或该 key 对象非哈希对象
|
||||
* error or not a hash key
|
||||
* >0 -- 域字段数量
|
||||
* the count of fields
|
||||
* 0 -- 该 key 不存在或域字段数量为 0
|
||||
* key not exists or no fields in hash stored at key
|
||||
*/
|
||||
int hlen(const char* key);
|
||||
|
||||
/**
|
||||
* 命令用于迭代哈希键中的键值对
|
||||
* scan the name and value of all fields in hash stored at key
|
||||
* @param key {const char*} 哈希键值
|
||||
* the hash key
|
||||
* @param cursor {int} 游标值,开始遍历时该值写 0
|
||||
* @param out {std::map<string>&} 存储结果集,内部以追加方式将本次
|
||||
* the cursor value, which is 0 at begin
|
||||
* @param out {std::map<acl::string>&} 存储结果集,内部以追加方式将本次
|
||||
* 遍历结果添加进该对象中,为防止因总结果集过大导致该数组溢出,用户可在
|
||||
* 调用本函数前后清理该对象
|
||||
* store scaning result in appending mode
|
||||
* @param pattern {const char*} 匹配模式,glob 风格,非空时有效
|
||||
* match pattern, effective only on no-NULL
|
||||
* @param count {const size_t*} 限定的结果集数量,非空指针时有效
|
||||
* the max count of one scan process, effective only on no-NULL
|
||||
* @return {int} 下一个游标位置,含义如下:
|
||||
* return the next cursor position, as below:
|
||||
* 0:遍历结束
|
||||
* scan finish
|
||||
* -1: 出错
|
||||
* some error happened
|
||||
* >0: 游标的下一个位置
|
||||
* the next cursor postion to scan
|
||||
*/
|
||||
int hscan(const char* key, int cursor, std::map<string, string>& out,
|
||||
const char* pattern = NULL, const size_t* count = NULL);
|
||||
|
@ -8,6 +8,7 @@ namespace acl
|
||||
{
|
||||
|
||||
class redis_client;
|
||||
class redis_client_cluster;
|
||||
|
||||
class ACL_CPP_API redis_hyperloglog : virtual public redis_command
|
||||
{
|
||||
@ -31,12 +32,20 @@ public:
|
||||
|
||||
/**
|
||||
* 将任意数量的元素添加到指定的 HyperLogLog 里面
|
||||
* add the specified elements to the specified HyperLogLog
|
||||
* @param key {const char*} 指定 key 值
|
||||
* the key
|
||||
* @param first_element {const char*} 元素集合的第一个元素值,非空字符串
|
||||
* the first element of the elements list, and the last must be NULL
|
||||
* in the elements list
|
||||
* @return {int} 操作是否成功,同时表明是否发生了变更,返回值含义如下:
|
||||
* return the follow values:
|
||||
* 1:操作成功,且数据发生了变更(新增数据或老数据发生变更)
|
||||
* successful, and the data was varied
|
||||
* 0:修改老数据未发生变化
|
||||
* nothing was changed after modifying the old data
|
||||
* -1:出错或对应的 key 对象非 hyperloglog 对象
|
||||
* error or the keh isn't a hyperloglog type
|
||||
*/
|
||||
int pfadd(const char* key, const char* first_element, ...);
|
||||
int pfadd(const char* key, const std::vector<const char*>& elements);
|
||||
@ -44,7 +53,11 @@ public:
|
||||
|
||||
/**
|
||||
* 获得给定键列表的 HyperLoglog 去重后元素的近似数量
|
||||
* return the approximated cardinality of the set(s) observed by
|
||||
* the hyperloglog at key(s)
|
||||
* @param first_key {const char*} key 集合的第一个 key,非空字符串
|
||||
* the firs key which must not be NULL of the keys list, and the
|
||||
* last parameter must be NULL in keys' list
|
||||
* @return {int} 键列表集合中经去重后元素的近似数量
|
||||
*/
|
||||
int pfcount(const char* first_key, ...);
|
||||
@ -54,10 +67,16 @@ public:
|
||||
/**
|
||||
* 将多个 HyperLogLog 合并(merge)为一个 HyperLogLog , 合并后的
|
||||
* HyperLogLog 的基数接近于所有输入 HyperLogLog 的可见集合的并集
|
||||
* merge multiple different hyperloglogs into a single one
|
||||
* @param dst {const char*} 目标存储 HyperLogLog 对象的键值
|
||||
* the single key as the destination
|
||||
* @param first_src {const char*} 源对象集合中第一个源 HyperLogLog 对象的键
|
||||
* the first source key which must not be NULL in the sources list,
|
||||
* and the last one must be NULL showing the end of the list
|
||||
* @return {bool} 操作是否成功,返回 false 表明出错或目标/源对象非
|
||||
* HyperLogLog 对象
|
||||
* true on success, false if the error or the dest/src are not
|
||||
* hyperloglog
|
||||
*/
|
||||
bool pfmerge(const char* dst, const char* first_src, ...);
|
||||
bool pfmerge(const char* dst, const std::vector<const char*>& keys);
|
||||
|
@ -7,12 +7,13 @@
|
||||
namespace acl {
|
||||
|
||||
class redis_client;
|
||||
class redis_client_cluster;
|
||||
|
||||
// redis 服务支持的数据类型分类
|
||||
// the data type supported by redis
|
||||
typedef enum
|
||||
{
|
||||
REDIS_KEY_UNKNOWN,
|
||||
REDIS_KEY_NONE,
|
||||
REDIS_KEY_NONE, // none
|
||||
REDIS_KEY_STRING, // string
|
||||
REDIS_KEY_HASH, // hash
|
||||
REDIS_KEY_LIST, // list
|
||||
@ -41,11 +42,19 @@ public:
|
||||
virtual ~redis_key();
|
||||
|
||||
/**
|
||||
* 删除一组 KEY,对于变参的接口,则要求最后一个参数必须以 NULL 结束
|
||||
* 删除一个或一组 KEY,对于变参的接口,则要求最后一个参数必须以 NULL 结束
|
||||
* delete one or some keys from redis, for deleting a variable
|
||||
* number of keys, the last key must be NULL indicating the end
|
||||
* of the variable args
|
||||
* @return {int} 返回所删除的 KEY 的个数,如下:
|
||||
* 0: 未删除任何 KEY
|
||||
* -1: 出错
|
||||
* >0: 真正删除的 KEY 的个数,该值有可能少于输入的 KEY 的个数
|
||||
* return the number of keys been deleted, return value as below:
|
||||
* 0: none key be deleted
|
||||
* -1: error happened
|
||||
* >0: the number of keys been deleted
|
||||
*
|
||||
*/
|
||||
int del_one(const char* key);
|
||||
int del_one(const char* key, size_t len);
|
||||
@ -58,44 +67,73 @@ public:
|
||||
/**
|
||||
* 序列化给定 key ,并返回被序列化的值,使用 RESTORE 命令可以将这个值反序列化
|
||||
* 为 Redis 键
|
||||
* serialize the object associate with the given key, and get the
|
||||
* value after serializing, RESTORE command can be used to
|
||||
* deserialize by the value
|
||||
* @param key {const char*} 键值
|
||||
* the key
|
||||
* @param out {string&} 存储序列化的二进制数据
|
||||
* buffur used to store the result
|
||||
* @return {int} 序列化后数据长度
|
||||
* the length of the data after serializing
|
||||
*/
|
||||
int dump(const char* key, string& out);
|
||||
|
||||
/**
|
||||
* 判断 KEY 是否存在
|
||||
* check if the key exists in redis
|
||||
* @param key {const char*} KEY 值
|
||||
* the key
|
||||
* @return {bool} 返回 true 表示存在,否则表示出错或不存在
|
||||
* true returned if key existing, false if error or not existing
|
||||
*/
|
||||
bool exists(const char* key);
|
||||
|
||||
/**
|
||||
* 设置 KEY 的生存周期,单位(秒)
|
||||
* set a key's time to live in seconds
|
||||
* @param key {const char*} 键值
|
||||
* the key
|
||||
* @param n {int} 生存周期(秒)
|
||||
* lief cycle in seconds
|
||||
* @return {int} 返回值含义如下:
|
||||
* return value as below:
|
||||
* > 0: 成功设置了生存周期
|
||||
* set successfully
|
||||
* 0:该 key 不存在
|
||||
* the key doesn't exist
|
||||
* < 0: 出错
|
||||
* error happened
|
||||
*/
|
||||
int expire(const char* key, int n);
|
||||
|
||||
/**
|
||||
* 用 UNIX 时间截设置 KEY 的生存周期
|
||||
* set the expiration for a key as a UNIX timestamp
|
||||
* @param key {const char*} 对象键值
|
||||
* the key
|
||||
* @param stamp {time_t} UNIX 时间截,即自 1970 年以来的秒数
|
||||
* an absolute Unix timestamp (seconds since January 1, 1970).
|
||||
* @return {int} 返回值的含义:
|
||||
* 1 -- 设置成功,0 -- 该 key 不存在,-1 -- 出错
|
||||
* return value:
|
||||
* 1: 设置成功
|
||||
* the timeout was set
|
||||
* 0: 该 key 不存在
|
||||
* the key doesn't exist or the timeout couldn't be set
|
||||
* -1: 出错
|
||||
* error happened
|
||||
*/
|
||||
int expireat(const char* key, time_t stamp);
|
||||
|
||||
/**
|
||||
* 查找所有符合给定模式 pattern 的 key
|
||||
* find all keys matching the given pattern
|
||||
* @param pattern {const char*} 匹配模式
|
||||
* the give matching pattern
|
||||
* @param out {std::vector<string>*} 非 NULL 时用来存储结果集
|
||||
* store the matched keys
|
||||
* @return {int} 结果集的数量,0--为空,<0 -- 表示出错
|
||||
* return the number of the matched keys, 0 if none, < 0 if error
|
||||
* 匹配模式举例:
|
||||
* KEYS * 匹配数据库中所有 key 。
|
||||
* KEYS h?llo 匹配 hello , hallo 和 hxllo 等。
|
||||
@ -117,151 +155,243 @@ public:
|
||||
|
||||
/**
|
||||
* 将数据从一个 redis-server 迁移至另一个 redis-server
|
||||
* atomically transfer a key from a redis instance to another one
|
||||
* @param key {const char*} 数据对应的键值
|
||||
* the key
|
||||
* @param addr {const char*} 目标 redis-server 服务器地址,格式:ip:port
|
||||
* the destination redis instance's address, format: ip:port
|
||||
* @param dest_db {unsigned} 目标 redis-server 服务器的数据库 ID 号
|
||||
* the databases ID in destination redis
|
||||
* @param timeout {unsigned} 迁移过程的超时时间(毫秒级)
|
||||
* timeout(microseconds) in transfering
|
||||
* @param option {const char*} COPY 或 REPLACE
|
||||
* transfer option: COPY or REPLACE
|
||||
* @return {bool} 迁移是否成功
|
||||
* if transfering successfully
|
||||
*/
|
||||
bool migrate(const char* key, const char* addr, unsigned dest_db,
|
||||
unsigned timeout, const char* option = NULL);
|
||||
|
||||
/**
|
||||
* 将数据移至本 redis-server 中的另一个数据库中
|
||||
* move a key to another database
|
||||
* @param key {const char*} 数据键值
|
||||
* the key
|
||||
* @param dest_db {unsigned} 目标数据库 ID 号
|
||||
* the destination database
|
||||
* @return {int} 迁移是否成功。-1: 表示出错,0:迁移失败,因为目标数据库中存在
|
||||
* 相同键值,1:迁移成功
|
||||
* if moving succcessfully. -1 if error, 0 if moving failed because
|
||||
* the same key already exists, 1 if successful
|
||||
*/
|
||||
int move(const char* key, unsigned dest_db);
|
||||
|
||||
/**
|
||||
* 返回给定 key 引用所储存的值的次数。此命令主要用于除错。
|
||||
* get the referring count of the object, which just for debugging
|
||||
* @param key {const char*} 数据键值
|
||||
* the key
|
||||
* @return {int} 返回 0 表示该 key 不存在;< 0 表示出错
|
||||
* 0 if key not exists, < 0 if error
|
||||
*/
|
||||
int object_refcount(const char* key);
|
||||
|
||||
/**
|
||||
* 返回给定 key 锁储存的值所使用的内部表示
|
||||
* 返回给定 key 键储存的值所使用的内部表示
|
||||
* get the internal storing of the object assosicate with the key
|
||||
* @param key {const char*} 数据键值
|
||||
* the key
|
||||
* @param out {string&} 存在结果
|
||||
* store the result
|
||||
* @return {bool} 是否成功
|
||||
* if successful
|
||||
*/
|
||||
bool object_encoding(const char* key, string& out);
|
||||
|
||||
/**
|
||||
* 返回给定 key 自储存以来的空闲时间(idle, 没有被读取也没有被写入),以秒为单位
|
||||
* get the key's idle time in seconds since its first stored
|
||||
* @param key {const char*} 数据键值
|
||||
* the key
|
||||
* @return {int} 返回值 < 0 表示出错
|
||||
* 0 if error happened
|
||||
*/
|
||||
int object_idletime(const char* key);
|
||||
|
||||
/**
|
||||
* 移除给定 key 的生存时间,将这个 key 从"易失的"(带生存时间 key )转换成
|
||||
* "持久的"(一个不带生存时间、永不过期的 key )
|
||||
* remove the expiration from a key
|
||||
* @param key {const char*} 对象键值
|
||||
* the key
|
||||
* @return {int} 返回值的含义如下:
|
||||
* 1 -- 设置成功,0 -- 该 key 不存在或未设置过期时间,-1 -- 出错
|
||||
* the value returned as below:
|
||||
* 1 -- 设置成功
|
||||
* set ok
|
||||
* 0 -- 该 key 不存在或未设置过期时间
|
||||
* the key not exists or not be set expiration
|
||||
* -1 -- 出错
|
||||
* error happened
|
||||
*/
|
||||
int persist(const char* key);
|
||||
|
||||
/**
|
||||
* 设置 KEY 的生存周期,单位(毫秒)
|
||||
* set a key's time to live in milliseconds
|
||||
* @param key {const char*} 键值
|
||||
* the key
|
||||
* @param n {int} 生存周期(毫秒)
|
||||
* time to live in milliseconds
|
||||
* @return {int} 返回值含义如下:
|
||||
* value returned as below:
|
||||
* > 0: 成功设置了生存周期
|
||||
* 0:该 key 不存在
|
||||
* set successfully
|
||||
* 0:该 key 不存在
|
||||
* the key doesn't exist
|
||||
* < 0: 出错
|
||||
* error happened
|
||||
*/
|
||||
int pexpire(const char* key, int n);
|
||||
|
||||
/**
|
||||
* 以毫秒为单位设置 key 的过期 unix 时间戳
|
||||
* set the expiration for a key as UNIX timestamp specified
|
||||
* in milliseconds
|
||||
* @param key {const char*} 键值
|
||||
* the key
|
||||
* @param n {long long int} UNIX 时间截,即自 1970 年以来的毫秒数
|
||||
* the UNIX timestamp in milliseconds from 1970.1.1
|
||||
* @return {int} 返回值含义如下:
|
||||
* value resturned as below:
|
||||
* > 0: 成功设置了生存周期
|
||||
* 0:该 key 不存在
|
||||
* set successfully
|
||||
* 0:该 key 不存在
|
||||
* the key doesn't exist
|
||||
* < 0: 出错
|
||||
* error happened
|
||||
*/
|
||||
int pexpireat(const char* key, long long int n);
|
||||
|
||||
/**
|
||||
* 获得 KEY 的剩余生存周期,单位(毫秒)
|
||||
* get the time to live for a key in milliseconds
|
||||
* @param key {const char*} 键值
|
||||
* the key
|
||||
* @return {int} 返回对应键值的生存周期
|
||||
* > 0: 该 key 剩余的生存周期(毫秒)
|
||||
* -3:出错
|
||||
* -2:key 不存在
|
||||
* -1:当 key 存在但没有设置剩余时间
|
||||
* value returned as below:
|
||||
* >0: 该 key 剩余的生存周期(毫秒)
|
||||
* the time to live for a key in milliseconds
|
||||
* -3:出错
|
||||
* error happened
|
||||
* -2:key 不存在
|
||||
* the key doesn't exist
|
||||
* -1:当 key 存在但没有设置剩余时间
|
||||
* th key were not be set expiration
|
||||
* 注:对于 redis-server 2.8 以前版本,key 不存在或存在但未设置生存期则返回 -1
|
||||
* notice: for redis version before 2.8, -1 will be returned if the
|
||||
* key doesn't exist or the key were not be set expiration.
|
||||
*/
|
||||
long long int pttl(const char* key);
|
||||
|
||||
/**
|
||||
* 从当前数据库中随机返回(不会删除)一个 key
|
||||
* return a random key from the keyspace
|
||||
*@param buf {string&} 成功获得随机 KEY 时存储结果
|
||||
* @return {bool} 操作是否成功,当出错或 key 不存在时返回 falsse
|
||||
* store the key
|
||||
* @return {bool} 操作是否成功,当出错或 key 不存在时返回 false
|
||||
* true on success, or false be returned
|
||||
*/
|
||||
bool randmkey(string& buf);
|
||||
|
||||
/**
|
||||
* 将 key 改名为 newkey
|
||||
* rename a key
|
||||
* @return {bool}
|
||||
* true on success, or error happened
|
||||
*/
|
||||
bool rename_key(const char* key, const char* newkey);
|
||||
|
||||
/**
|
||||
* 当且仅当 newkey 不存在时,将 key 改名为 newkey
|
||||
* rename a key only if the new key does not exist
|
||||
* @param key {const char*} 旧 key
|
||||
* @param newkey {const char*} 新 key
|
||||
* @return {bool} 是否成功
|
||||
* true on success, false if the newkey already existed or error
|
||||
*/
|
||||
bool renamenx(const char* key, const char* newkey);
|
||||
|
||||
/**
|
||||
* 反序列化给定的序列化值,并将它和给定的 key 关联
|
||||
* create a key using the provided serialized value, previously
|
||||
* obtained by using DUMP
|
||||
* @param ttl {int} 以毫秒为单位为 key 设置生存时间,如果 ttl 为 0,
|
||||
* 那么不设置生存时间
|
||||
* the time to live for the key in milliseconds, if tll is 0,
|
||||
* expiration will not be set
|
||||
* @param replace {bool} 如果 key 存在是否直接覆盖
|
||||
* if the key already exists, this parameter decides if replacing
|
||||
* the existing key
|
||||
* @return {bool}
|
||||
* true on success, false on error
|
||||
*/
|
||||
bool restore(const char* key, const char* value, size_t len,
|
||||
int ttl, bool replace = false);
|
||||
|
||||
/**
|
||||
* 获得 KEY 的剩余生存周期,单位(秒)
|
||||
* get the time to live for a key in seconds
|
||||
* @param key {const char*} 键值
|
||||
* the key
|
||||
* @return {int} 返回对应键值的生存周期
|
||||
* return value as below:
|
||||
* > 0: 该 key 剩余的生存周期(秒)
|
||||
* -3:出错
|
||||
* -2:key 不存在
|
||||
* -1:当 key 存在但没有设置剩余时间
|
||||
* the time to live for a key in seconds
|
||||
* -3:出错
|
||||
* error happened
|
||||
* -2:key 不存在
|
||||
* the key doesn't exist
|
||||
* -1:当 key 存在但没有设置剩余时间
|
||||
* the key were not be set expiration
|
||||
* 注:对于 redis-server 2.8 以前版本,key 不存在或存在但未设置生存期则返回 -1
|
||||
* notice: for the redis version before 2.8, -1 will be returned
|
||||
* if the key doesn't exist or the key were not be set expiration
|
||||
*/
|
||||
int ttl(const char* key);
|
||||
|
||||
/**
|
||||
* 获得 KEY 的存储类型
|
||||
* get the the type stored at key
|
||||
* @para key {const char*} KEY 值
|
||||
* the key
|
||||
* @return {redis_key_t} 返回 KEY 的存储类型
|
||||
* return redis_key_t defined above as REDIS_KEY_
|
||||
*/
|
||||
redis_key_t type(const char* key);
|
||||
|
||||
/**
|
||||
* 命令用于迭代当前数据库中的数据库键
|
||||
* incrementally iterate the keys space in the specified database
|
||||
* @param cursor {int} 游标值,开始遍历时该值写 0
|
||||
* @param out {std::vector<string>&} 存储结果集,内部以追加方式将本次
|
||||
* the iterating cursor beginning with 0
|
||||
* @param out {std::vector<acl::string>&} 存储结果集,内部以追加方式将本次
|
||||
* 遍历结果集合添加进该数组中,为防止因总结果集过大导致该数组溢出,用户可在
|
||||
* 调用本函数前后清理该数组对象
|
||||
* string array storing the results, the array will be cleared
|
||||
* internal and the string result will be appened to the array
|
||||
* @param pattern {const char*} 匹配模式,glob 风格,非空时有效
|
||||
& the matching pattern with glob style, only effective if not NULL
|
||||
* @param count {const size_t*} 限定的结果集数量,非空指针时有效
|
||||
* limit the max number of the results stored in array, only
|
||||
* effective when not NULL
|
||||
* @return {int} 下一个游标位置,含义如下:
|
||||
* return the next cursor value as follow:
|
||||
* 0:遍历结束
|
||||
* iterating is finished
|
||||
* -1: 出错
|
||||
* some error happened
|
||||
* >0: 游标的下一个位置
|
||||
* the next cursor value for iterating
|
||||
*/
|
||||
int scan(int cursor, std::vector<string>& out,
|
||||
const char* pattern = NULL, const size_t* count = NULL);
|
||||
|
@ -35,13 +35,21 @@ public:
|
||||
|
||||
/**
|
||||
* 将信息发送到指定的频道 channel
|
||||
* post a message to a channel
|
||||
* @param channel {const char*} 所发送消息的目标频道
|
||||
* the specified channel
|
||||
* @param msg {const char*} 消息内容
|
||||
* the message to be sent
|
||||
* @param len {size_t} 消息长度
|
||||
* the message's length
|
||||
* @return {int} 成功发送至订阅该频道的订阅者数量
|
||||
* the number of clients that received the message
|
||||
* -1:表示出错
|
||||
* error happened
|
||||
* 0:没有订阅者
|
||||
* no client subscribe the channel
|
||||
* >0:订阅该频道的订阅者数量
|
||||
* the number of clients that received the message
|
||||
*/
|
||||
int publish(const char* channel, const char* msg, size_t len);
|
||||
|
||||
@ -49,9 +57,16 @@ public:
|
||||
* 订阅给定的一个或多个频道的信息;在调用本函数后的操作只能发送的命令有:
|
||||
* subscribe、unsubscribe、psubscribe、punsubscribe、get_message,只有
|
||||
* 取消订阅了所有频道(或连接重建)后才摆脱该限制
|
||||
* subscribe one or more channel(s). Once the client enters the
|
||||
* subscribed state it is not supposed to issue any other commands,
|
||||
* except for additional SUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE
|
||||
* and PUNSUBSCRIBE commands
|
||||
* @param first_channel {const char*} 所订阅的频道列表的第一个非空字符串
|
||||
* 的频道,对于变参列表中的最后一个必须是 NULL
|
||||
* the first non-NULL channel in the channel list, and the last
|
||||
* parameter must be NULL indicating the end of the channel list
|
||||
* @return {int} 返回当前已经成功订阅的频道个数(即所订阅的所有频道数量)
|
||||
* the number of channels subscribed by the current client
|
||||
*/
|
||||
int subscribe(const char* first_channel, ...);
|
||||
int subscribe(const std::vector<const char*>& channels);
|
||||
@ -59,8 +74,12 @@ public:
|
||||
|
||||
/**
|
||||
* 取消订阅给定的一个或多个频道的信息
|
||||
* stop listening for messages posted to the given channels
|
||||
* @param first_channel {const char*} 所取消的所订阅频道列表的第一个频道
|
||||
* the fist channel in channel list, and the last parameter must be
|
||||
* NULL indicating the end of the channel list
|
||||
* @return {int} 返回剩余的所订阅的频道的个数
|
||||
* the rest channels listened by the current client
|
||||
*/
|
||||
int unsubscribe(const char* first_channel, ...);
|
||||
int unsubscribe(const std::vector<const char*>& channels);
|
||||
@ -68,11 +87,14 @@ public:
|
||||
|
||||
/**
|
||||
* 订阅一个或多个符合给定模式的频道;每个模式以 * 作为匹配符;在调用本函数后的操作
|
||||
* 只能发送的命令有:
|
||||
* subscribe、unsubscribe、psubscribe、punsubscribe、get_message,只有
|
||||
* 取消订阅了所有频道(或连接重建)后才摆脱该限制
|
||||
* 只能发送的命令有:subscribe、unsubscribe、psubscribe、punsubscribe、
|
||||
* get_message,只有取消订阅了所有频道(或连接重建)后才摆脱该限制
|
||||
* listen for messages published to channels matching the give patterns
|
||||
* @param first_pattern {const char*} 第一个匹配模式串
|
||||
* the first pattern in pattern list, the last parameter must be NULL
|
||||
* int the variable args
|
||||
* @return {int} 返回当前已经成功订阅的频道个数(即所订阅的所有频道数量)
|
||||
* the number of channels listened by the current client
|
||||
*/
|
||||
int psubscribe(const char* first_pattern, ...);
|
||||
int psubscribe(const std::vector<const char*>& patterns);
|
||||
@ -80,29 +102,42 @@ public:
|
||||
|
||||
/**
|
||||
* 根据模式匹配串取消订阅给定的一个或多个频道的信息
|
||||
* stop listening for messaged posted to channels matching
|
||||
* the given patterns
|
||||
* @param first_pattern {const char*} 第一个匹配模式串
|
||||
* the first parttern in a variable args ending with NULL
|
||||
* @return {int} 返回剩余的所订阅的频道的个数
|
||||
* the rest number of channels be listened by the client
|
||||
*/
|
||||
int punsubscribe(const char* first_pattern, ...);
|
||||
int punsubscribe(const std::vector<const char*>& patterns);
|
||||
int punsubscribe(const std::vector<string>& patterns);
|
||||
|
||||
/**
|
||||
* 在订阅频道后可以循环调用本函数从所订阅的频道中获取订阅消息;在调用 subscribe
|
||||
* 或 psubscribe 后才可调用本函数来获取所订阅的频道的消息
|
||||
* 在订阅频道后可以循环调用本函数从所订阅的频道中获取订阅消息;
|
||||
* 在调用 subscribe 或 psubscribe 后才可调用本函数来获取所订阅的频道的消息
|
||||
* get messages posted to channels after SUBSCRIBE or PSUBSCRIBE
|
||||
* @param channel {string&} 存放当前有消息的频道名
|
||||
* buffer for storing the channel associate with the msg
|
||||
* @param msg {string&} 存放当前获得的消息内容
|
||||
* store the message posted to the channel
|
||||
* @return {bool} 是否成功,如果返回 false 则表示出错
|
||||
* true on success, false on error
|
||||
*/
|
||||
bool get_message(string& channel, string& msg);
|
||||
|
||||
/**
|
||||
* 列出当前的活跃频道:活跃频道指的是那些至少有一个订阅者的频道, 订阅模式的
|
||||
* 客户端不计算在内
|
||||
* Lists the currently active channels.
|
||||
* @param channels {std::vector<string>*} 非空时存放频道结果集
|
||||
* store the active channels
|
||||
* @param first_pattern {const char*} 作为附加的匹配模式第一个匹配字符串,
|
||||
* 该指针可以为 NULL,此时获取指所有的活跃频道;对于变参而言最后一个参数需为 NULL
|
||||
* the first pattern in a variable args ending with NULL arg, and
|
||||
* the first arg can be NULL.
|
||||
* @return {int} 返回活跃频道数; -1 表示出错
|
||||
* the number of active channels. -1 if error
|
||||
*
|
||||
* 操作成功后可以通过以下任一方式获得数据
|
||||
* 1、基类方法 get_value 获得指定下标的元素数据
|
||||
@ -125,10 +160,15 @@ public:
|
||||
|
||||
/**
|
||||
* 返回给定频道的订阅者数量, 订阅模式的客户端不计算在内
|
||||
* Returns the number of subscribers (not counting clients
|
||||
* subscribed to patterns) for the specified channels.
|
||||
* @param out {std::map<string, int>&} 存储查询结果,其中 out->first 存放
|
||||
* 频道名,out->second 在座该频道的订阅者数量
|
||||
* store the results
|
||||
* @param first_pattern {const char*} 作为附加的匹配模式第一个匹配字符串,
|
||||
* 该指针可以为 NULL,此时获取指所有的活跃频道;对于变参而言最后一个参数需为 NULL
|
||||
* the first pattern in a variable args ending with NULL arg, and
|
||||
* the first arg can be NULL.
|
||||
* @return {int} 频道的数量,-1 表示出错
|
||||
*/
|
||||
int pubsub_numsub(std::map<string, int>& out,
|
||||
@ -141,7 +181,10 @@ public:
|
||||
/**
|
||||
* 返回订阅模式的数量,这个命令返回的不是订阅模式的客户端的数量, 而是客户端订阅的
|
||||
* 所有模式的数量总和
|
||||
* Returns the number of subscriptions to patterns.
|
||||
* @return {int} 客户端所有订阅模式的总和,-1 表示出错
|
||||
* the number of patterns all the clients are subscribed to,
|
||||
* -1 if error.
|
||||
*/
|
||||
int pubsub_numpat();
|
||||
|
||||
|
@ -23,7 +23,7 @@ class redis_client;
|
||||
/**
|
||||
* 对 redis-server 返回结果对象类,对 redis-server 返回的数据进行分析后创建
|
||||
* redis_result 类对象。
|
||||
* the redis result for redis-server's respond
|
||||
* the redis result for redis-server's reply
|
||||
*/
|
||||
class ACL_CPP_API redis_result
|
||||
{
|
||||
@ -33,13 +33,17 @@ public:
|
||||
/**
|
||||
* 重载了 new/delete 操作符,在 new 新对象时,使内存的分配在
|
||||
* 内存池进行分配
|
||||
* override new/delete operator, when the new object was created,
|
||||
* memory was alloc in dbuf_pool, which is a memroy pool allocator
|
||||
*/
|
||||
void *operator new(size_t size, dbuf_pool* pool);
|
||||
void operator delete(void* ptr, dbuf_pool* pool);
|
||||
|
||||
/**
|
||||
* 获得当前结果结点的数据类型
|
||||
* get the data type of the reply from redis-server
|
||||
* @return {redis_result_t}
|
||||
* defined above REDIS_RESULT_
|
||||
*/
|
||||
redis_result_t get_type() const
|
||||
{
|
||||
@ -48,7 +52,9 @@ public:
|
||||
|
||||
/**
|
||||
* 获得当前结果结点存储的对象的个数
|
||||
* get the number of objects from redis-server
|
||||
* @return {size_t} 返回值与存储类型的对应关系如下:
|
||||
* the relation between returned value and result type show below:
|
||||
* REDIS_RESULT_ERROR: 1
|
||||
* REDIS_RESULT_STATUS: 1
|
||||
* REDIS_RESULT_INTEGER: 1
|
||||
@ -59,40 +65,54 @@ public:
|
||||
|
||||
/**
|
||||
* 当返回值为 REDIS_RESULT_INTEGER 类型时,本方法返回对应的 32 位整数值
|
||||
* get the 32 bits integer for REDIS_RESULT_INTEGER result
|
||||
* @param success {bool*} 本指针非 NULL 时记录操作过程是否成功
|
||||
* when not NULL, storing the status of success
|
||||
* @return {int}
|
||||
*/
|
||||
int get_integer(bool* success = NULL) const;
|
||||
|
||||
/**
|
||||
* 当返回值为 REDIS_RESULT_INTEGER 类型时,本方法返回对应的 64 位整数值
|
||||
* get the 64 bits integer for REDIS_RESULT_INTEGER result
|
||||
* @param success {bool*} 本指针非 NULL 时记录操作过程是否成功
|
||||
* when not NULL, storing the status of success
|
||||
* @return {long long int}
|
||||
*/
|
||||
long long int get_integer64(bool* success = NULL) const;
|
||||
|
||||
/**
|
||||
* 当返回值为 REDIS_RESULT_STATUS 类型时,本方法返回状态信息
|
||||
* get operation status for REDIS_RESULT_STATUS result
|
||||
* @return {const char*} 返回 "" 表示出错
|
||||
* error if empty string returned
|
||||
*/
|
||||
const char* get_status() const;
|
||||
|
||||
/**
|
||||
* 当出错时返回值为 REDIS_RESULT_ERROR 类型,本方法返回出错信息
|
||||
* when some error happened, this can get the error information
|
||||
* @return {const char*} 返回空串 "" 表示没有出错信息
|
||||
* there was no error information if empty string returned
|
||||
*/
|
||||
const char* get_error() const;
|
||||
|
||||
/**
|
||||
* 返回对应下标的数据(当数据类型非 REDIS_RESULT_ARRAY 时)
|
||||
* get the string data of associated subscript(just for the type
|
||||
* of no REDIS_RESULT_ARRAY)
|
||||
* @param i {size_t} 数组下标
|
||||
* the array's subscript
|
||||
* @param len {size_t*} 当为非 NULL 指针时存储所返回数据的长度
|
||||
* when not NULL, the parameter will store the length of the result
|
||||
* @return {const char*} 返回 NULL 表示下标越界
|
||||
* NULL if nothing exists or the subscript is out of bounds
|
||||
*/
|
||||
const char* get(size_t i, size_t* len = NULL) const;
|
||||
|
||||
/**
|
||||
* 返回所有的数据数组(当数据类型非 REDIS_RESULT_ARRAY 时)地址
|
||||
* return all data's array if the type isn't REDIS_RESULT_ARRAY
|
||||
* @return {const char**}
|
||||
*/
|
||||
const char** gets_argv() const
|
||||
@ -102,6 +122,7 @@ public:
|
||||
|
||||
/**
|
||||
* 返回所有的数据长度数组(当数据类型非 REDIS_RESULT_ARRAY 时)地址
|
||||
* return all length's array if the type isn't REDIS_RESULT_ARRAY
|
||||
* @return {const size_t*}
|
||||
*/
|
||||
const size_t* get_lens() const
|
||||
@ -111,6 +132,7 @@ public:
|
||||
|
||||
/**
|
||||
* 返回所有数据的总长度(当数据类型非 REDIS_RESULT_ARRAY 时)
|
||||
* return the total length of all data for no REDIS_RESULT_ARRAY
|
||||
* @return {size_t}
|
||||
*/
|
||||
size_t get_length() const;
|
||||
@ -118,28 +140,37 @@ public:
|
||||
/**
|
||||
* 当数据类型为 REDIS_RESULT_STRING 类型时,该函数将按内存块存放的数据
|
||||
* 存储至连接内存中,但需要注意防止内存溢出
|
||||
* compose a continus data for the slicing chunk data internal
|
||||
* @param buf {string&} 存储结果数据,内部会先调用 buf.clear()
|
||||
* store the result
|
||||
* @return {int} 数据的总长度,返回值 -1 表示内部数组为空
|
||||
* return the total length of data, -1 if data array has no elements
|
||||
*/
|
||||
int argv_to_string(string& buf) const;
|
||||
int argv_to_string(char* buf, size_t size) const;
|
||||
|
||||
/**
|
||||
* 当数据类型为 REDIS_RESULT_ARRAY 类型时,该函数返回所有的数组对象
|
||||
* return the objects array when result type is REDIS_RESULT_ARRAY
|
||||
* @param size {size_t*} 当返回数组非空时,则该地址存放数组长度
|
||||
* store the array's length if size isn't NULL
|
||||
* @return {const const redis_result*}
|
||||
*/
|
||||
const redis_result** get_children(size_t* size) const;
|
||||
|
||||
/**
|
||||
* 当数据类型为 REDIS_RESULT_ARRAY 类型时,该函数返回对应下标的结果对象
|
||||
* get one object of the given subscript from objects array
|
||||
* @param i {size_t} 下标值
|
||||
* the given subscript
|
||||
* @return {const redis_result*} 当下标值越界或结果不存在时,则返回 NULL
|
||||
* NULL if subscript is out of bounds or object not exist
|
||||
*/
|
||||
const redis_result* get_child(size_t i) const;
|
||||
|
||||
/**
|
||||
* 返回构造函数传入的内存池对象
|
||||
* get the memory pool object set in constructor
|
||||
* @return {dbuf_pool*}
|
||||
*/
|
||||
dbuf_pool* get_pool()
|
||||
|
@ -8,34 +8,78 @@ namespace acl
|
||||
class ACL_CPP_API redis_slot
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* 构造函数
|
||||
* constructor
|
||||
* @param slot_min {size_t} 最小哈希槽值
|
||||
* the min hash-slot
|
||||
* @param slot_max {size_t} 最大哈希槽值
|
||||
* the max hash-slot
|
||||
* @param ip {const char*} 当前 redis-server 的 IP 地址
|
||||
* the given redis-server's ip
|
||||
* @param port {int} 当前 redis-server 的监听端口
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* 将一个 redis 哈希槽从结点添加至当前结点中
|
||||
* add a slave slot node to the current node
|
||||
* @param node {redis_slot*} 一个存储哈希槽的从结点
|
||||
* the slave slot node
|
||||
*/
|
||||
redis_slot& add_slave(redis_slot* node);
|
||||
|
||||
/**
|
||||
* 获得当前哈希槽结点的所有从结点
|
||||
* get the slave nodes of the current node
|
||||
* @return {const std::vector<redis_slot*>&}
|
||||
*/
|
||||
const std::vector<redis_slot*>& get_slaves() const
|
||||
{
|
||||
return slaves_;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前结点的 IP 地址
|
||||
* get the ip of the current node
|
||||
* @return {const char*}
|
||||
*/
|
||||
const char* get_ip() const
|
||||
{
|
||||
return ip_;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前结点的端口号
|
||||
* get the port of the current node
|
||||
* @return {int}
|
||||
*/
|
||||
int get_port() const
|
||||
{
|
||||
return port_;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前哈希槽结点的最小值
|
||||
* get the min hash slot of the current node
|
||||
* @return {size_t}
|
||||
*/
|
||||
size_t get_slot_min() const
|
||||
{
|
||||
return slot_min_;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前哈希槽结点的最大值
|
||||
* get the max hash slot of the current node
|
||||
* @return {size_t}
|
||||
*/
|
||||
size_t get_slot_max() const
|
||||
{
|
||||
return slot_max_;
|
||||
|
@ -35,21 +35,30 @@ public:
|
||||
/**
|
||||
* 监视一个(或多个) key ,如果在事务执行之前这个(或这些) key 被其他命令所改动,
|
||||
* 那么事务将被打断
|
||||
* watch the given keys to determine execution of the MULTI/EXEC
|
||||
* block, before EXEC some of the given keys were changed outer,
|
||||
* the transaction will break
|
||||
* @param keys {const std::vector<string>&} key 集合
|
||||
* the given keys collection
|
||||
* @return {bool} 操作是否成功,即使 key 集合中的有 key 不存在也会返回成功
|
||||
* if success of this operation
|
||||
*/
|
||||
bool watch(const std::vector<string>& keys);
|
||||
|
||||
/**
|
||||
* 取消 WATCH 命令对所有 key 的监视
|
||||
* forget about all watched keys
|
||||
* @return {bool} 操作是否成功
|
||||
* if success of this operation
|
||||
*/
|
||||
bool unwatch();
|
||||
|
||||
/**
|
||||
* 标记一个事务块的开始,事务块内的多条命令会按照先后顺序被放进一个队列当中,
|
||||
* 最后由 EXEC 命令原子性(atomic)地执行
|
||||
* mark the start of a transaction block
|
||||
* @return {bool} 操作是否成功
|
||||
* if success of this operation
|
||||
*/
|
||||
bool multi();
|
||||
|
||||
@ -59,52 +68,72 @@ public:
|
||||
* key 没有被其他命令所改动的情况下执行并生效,否则该事务被打断(abort);
|
||||
* 在执行本条命令成功后,可以调用下面的 get_size()/get_child() 获得每条命令的
|
||||
* 操作结果
|
||||
* execute all commands issued after MULTI
|
||||
* @return {bool} 操作是否成功
|
||||
* if success of this operation
|
||||
*/
|
||||
bool exec();
|
||||
|
||||
/**
|
||||
* 取消事务,放弃执行事务块内的所有命令,如果正在使用 WATCH 命令监视某个(或某些)
|
||||
* key,那么取消所有监视,等同于执行命令 UNWATCH
|
||||
* discard all commands issued after MULTI
|
||||
* @return {bool}
|
||||
*/
|
||||
bool discard();
|
||||
|
||||
/**
|
||||
* 在 multi 和 exec 之间执行多条 redis 客户端命令
|
||||
* 在 multi 和 exec 之间可多次调用本函数执行多条 redis 客户端命令
|
||||
* run one command between MULTI and EXEC
|
||||
* @param cmd {const char*} redis 命令
|
||||
* the command
|
||||
* @param argv {const char* []} 参数数组
|
||||
* the args array associate with the command
|
||||
* @param lens [const size_t []} 参数的长度数组
|
||||
* the length array of the args array
|
||||
* @param argc {size_t} 参数数组的长度
|
||||
* the length of the array for args
|
||||
* @return {bool} 操作是否成功
|
||||
* if successful
|
||||
*/
|
||||
bool run_cmd(const char* cmd, const char* argv[],
|
||||
const size_t lens[], size_t argc);
|
||||
|
||||
/**
|
||||
* 在 multi 和 exec 之间执行多条 redis 客户端命令
|
||||
* 在 multi 和 exec 之间多次调用本函数执行多条 redis 客户端命令
|
||||
* run one command between MULTI and exec, this function can be
|
||||
* called more than once
|
||||
* @param cmd {const char*} redis 命令
|
||||
* the redis command
|
||||
* @param args {const std::vector<string>&} 参数数组
|
||||
* the args array for the command
|
||||
* @return {bool} 操作是否成功
|
||||
* if successful
|
||||
*/
|
||||
bool run_cmd(const char* cmd, const std::vector<string>& args);
|
||||
|
||||
/**
|
||||
* 在成功调用 exec 后调用本函数获得操作结果数组的长度
|
||||
* get the result array's length after EXEC
|
||||
* @return {size_t}
|
||||
*/
|
||||
size_t get_size() const;
|
||||
|
||||
/**
|
||||
* 获取指定下标的对应的命令的执行结果对象
|
||||
* get the result of the given subscript
|
||||
* @param i {size_t} 命令执行结果在结果数组中的下标
|
||||
* the given subscript
|
||||
* @param cmd {string*} 该参数非空时存放对应的 redis 命令
|
||||
* @return {const redis_result*} 执行的某条命令的结果对象,
|
||||
* 当 i 越界时返回 NULL
|
||||
* if not NULL, it will store the command of the given subscript
|
||||
* @return {const redis_result*} 执行某条命令的结果,当 i 越界时返回 NULL
|
||||
* return the result of one command, NULL if i was out of bounds
|
||||
*/
|
||||
const redis_result* get_child(size_t i, string* cmd) const;
|
||||
|
||||
/**
|
||||
* 获得当前事务所重的命令集合
|
||||
* get all the commands issued between MULTI and EXEC
|
||||
* @return {const std::vector<string>&}
|
||||
*/
|
||||
const std::vector<string>& get_commands() const
|
||||
|
@ -389,10 +389,7 @@ redis_key_t redis_key::type(const char* key)
|
||||
build_request(2, argv, lens);
|
||||
const char* ptr = get_status();
|
||||
|
||||
if (ptr == NULL || *ptr == 0)
|
||||
return REDIS_KEY_UNKNOWN;
|
||||
|
||||
if (strcasecmp(ptr, "none") == 0)
|
||||
if (ptr == NULL || *ptr == 0 || strcasecmp(ptr, "none") == 0)
|
||||
return REDIS_KEY_NONE;
|
||||
else if (strcasecmp(ptr, "string") == 0)
|
||||
return REDIS_KEY_STRING;
|
||||
@ -405,7 +402,7 @@ redis_key_t redis_key::type(const char* key)
|
||||
else
|
||||
{
|
||||
logger_error("unknown type: %s, key: %s", ptr, key);
|
||||
return REDIS_KEY_UNKNOWN;
|
||||
return REDIS_KEY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user