add some comments for redis module

This commit is contained in:
ubuntu14 2015-04-12 06:37:17 -07:00
parent d6933c5694
commit cd4802771d
11 changed files with 476 additions and 47 deletions

View File

@ -1,6 +1,9 @@
修改历史列表:
------------------------------------------------------------------------
300) 2015.4.12
300.1) comment: 完善了 redis 模块的英文注释
299) 2015.4.8
299.1) comment: 给 redis 模块增加了一些注释

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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
* -2key
* -1 key
* value returned as below:
* >0: key
* the time to live for a key in milliseconds
* -3
* error happened
* -2key
* 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
* -2key
* -1 key
* the time to live for a key in seconds
* -3
* error happened
* -2key
* 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);

View File

@ -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:
*
* subscribeunsubscribepsubscribepunsubscribeget_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:
/**
* *
*
* subscribeunsubscribepsubscribepunsubscribeget_message
*
* subscribeunsubscribepsubscribepunsubscribe
* 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();

View File

@ -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()

View File

@ -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_;

View File

@ -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

View File

@ -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;
}
}