add comment for redis client API

This commit is contained in:
zsx 2015-01-28 17:28:45 +08:00
parent 2a373c4e71
commit 13bcb6aefb
12 changed files with 720 additions and 115 deletions

View File

@ -55,7 +55,8 @@ public:
int get_strings(std::vector<string>& result);
int get_strings(std::vector<string>* result);
int get_strings(std::map<string, string>& result);
int get_strings(std::vector<string>& names, std::vector<string>& values);
int get_strings(std::vector<string>& names,
std::vector<string>& values);
int get_strings(std::vector<const char*>& names,
std::vector<const char*>& values);

View File

@ -15,14 +15,36 @@ public:
redis_hyperloglog(redis_client* conn = NULL);
~redis_hyperloglog();
/**
* HyperLogLog
* @param key {const char*} key
* @param first_element {const char*}
* @return {int}
* 1
* 0
* -1 key hyperloglog
*/
int pfadd(const char* key, const char* first_element, ...);
int pfadd(const char* key, const std::vector<const char*>& elements);
int pfadd(const char* key, const std::vector<string>& elements);
/**
* HyperLoglog
* @param first_key {const char*} key key
* @return {int}
*/
int pfcount(const char* first_key, ...);
int pfcount(const std::vector<const char*>& keys);
int pfcount(const std::vector<string>& keys);
/**
* HyperLogLog merge HyperLogLog
* HyperLogLog HyperLogLog
* @param dst {const char*} HyperLogLog
* @param first_src {const char*} HyperLogLog
* @return {bool} false /
* HyperLogLog
*/
bool pfmerge(const char* dst, const char* first_src, ...);
bool pfmerge(const char* dst, const std::vector<const char*>& keys);
bool pfmerge(const char* dst, const std::vector<string>& keys);

View File

@ -15,43 +15,21 @@ public:
/////////////////////////////////////////////////////////////////////
int llen(const char* key);
bool lindex(const char* key, size_t idx, string& buf,
bool* exist = NULL);
bool lset(const char* key, size_t idx, const char* value);
bool lset(const char* key, size_t idx, const char* value, size_t len);
int linsert_before(const char* key, const char* pivot,
const char* value);
int linsert_before(const char* key, const char* pivot,
size_t pivot_len, const char* value, size_t value_len);
int linsert_after(const char* key, const char* pivot,
const char* value);
int linsert_after(const char* key, const char* pivot,
size_t pivot_len, const char* value, size_t value_len);
int lpush(const char* key, const char* first_value, ...);
int lpush(const char* key, const char* values[], size_t argc);
int lpush(const char* key, const std::vector<string>& values);
int lpush(const char* key, const std::vector<const char*>& values);
int lpush(const char* key, const char* values[], size_t lens[],
size_t argc);
int rpush(const char* key, const char* first_value, ...);
int rpush(const char* key, const char* values[], size_t argc);
int rpush(const char* key, const std::vector<string>& values);
int rpush(const char* key, const std::vector<const char*>& values);
int rpush(const char* key, const char* values[], size_t lens[],
size_t argc);
int lpushx(const char* key, const char* value);
int lpushx(const char* key, const char* value, size_t len);
int rpushx(const char* key, const char* value);
int rpushx(const char* key, const char* value, size_t len);
int lpop(const char* key, string& buf);
int rpop(const char* key, string& buf);
/**
* key name/value对
* key key
*
* @param result {std::pair<string, string>&}
* key
* @param timeout {size_t}
* false 0
* @param first_key {const char*} key
* @return {bool} false
* 1
* 2 key
* 3key
*/
bool blpop(std::pair<string, string>& result, size_t timeout,
const char* first_key, ...);
bool blpop(const std::vector<const char*>& keys, size_t timeout,
@ -59,6 +37,10 @@ public:
bool blpop(const std::vector<string>& keys, size_t timeout,
std::pair<string, string>& result);
/**
* blpop
* @sess blpop
*/
bool brpop(std::pair<string, string>& result, size_t timeout,
const char* first_key, ...);
bool brpop(const std::vector<const char*>& keys, size_t timeout,
@ -66,17 +48,205 @@ public:
bool brpop(const std::vector<string>& keys, size_t timeout,
std::pair<string, string>& result);
bool rpoplpush(const char* src, const char* dst, string* buf = NULL);
/**
*
* 1) src ()
* 2) src dst dst
* @param src {const char*} key
* @param dst {const char*} key
* @param buf {string*} src key
* @param timeout {size_t} 0
* @return {bool} src dst
* true false src/dst
* @see rpoplpush
*/
bool brpoplpush(const char* src, const char* dst, size_t timeout,
string* buf = NULL);
bool lrange(const char* key, size_t start, size_t end,
/**
* key
* @param key {const char*} key
* @param idx {size_t}
* @param buf {string&}
* @return {bool} true buf
* buf.empty() false
*/
bool lindex(const char* key, size_t idx, string& buf);
/**
*
* @param key {const char*} key
* @param pivot {const char*}
* @param value {const char*}
* @reutrn {int}
* -1 -- key
* >0 --
*/
int linsert_before(const char* key, const char* pivot,
const char* value);
int linsert_before(const char* key, const char* pivot,
size_t pivot_len, const char* value, size_t value_len);
/**
*
* @param key {const char*} key
* @param pivot {const char*}
* @param value {const char*}
* @reutrn {int}
* -1 -- key
* >0 --
*/
int linsert_after(const char* key, const char* pivot,
const char* value);
int linsert_after(const char* key, const char* pivot,
size_t pivot_len, const char* value, size_t value_len);
/**
*
* @param key {const char*} key
* @return {int}
*/
int llen(const char* key);
/**
*
* @param key {const char*} key
* @param buf {string&}
* @return {int} 1 -- -1 --
*
*/
int lpop(const char* key, string& buf);
/**
* key
* @param key {const char*} key
* @param first_value {const char*}
* NULL
* @return {int} -1 key
* key
*/
int lpush(const char* key, const char* first_value, ...);
int lpush(const char* key, const char* values[], size_t argc);
int lpush(const char* key, const std::vector<string>& values);
int lpush(const char* key, const std::vector<const char*>& values);
int lpush(const char* key, const char* values[], size_t lens[],
size_t argc);
/**
*
*
* @param key {const char*} key
* @param value {const char*}
* @return {int}
* -1 key
* 0 key
* >0
*/
int lpushx(const char* key, const char* value);
int lpushx(const char* key, const char* value, size_t len);
/**
* key start end
* 0 -1
* @param key {const char*} key
* @param start {int}
* @param end {int}
* @param result {std::vector<string>&}
* @return {bool} false key
*
* 1) start = 0, end = 10 0 10 11
* 2) start = -1, end = -2 2
*/
bool lrange(const char* key, int start, int end,
std::vector<string>& result);
/**
*
* @param key {const char*} key
* @param count {int} count
* count > 0 : value count
* count < 0 : value count
* count = 0 : value
* @param value {const char*}
* @return {int}
* -1 key
* 0key 0
* >0
*/
int lrem(const char* key, int count, const char* value);
int lrem(const char* key, int count, const char* value, size_t len);
bool ltrim(const char* key, size_t start, size_t end);
/**
* key idx value idx
* ( key ) lset
* @param key {const char*} key
* @param idx {int}
* 0 -1
* @param value {const char*}
* @return {bool} key key idx false
*/
bool lset(const char* key, int idx, const char* value);
bool lset(const char* key, int idx, const char* value, size_t len);
/**
* start end
* 0 -1
* @param key {const char*} key
* @param start {int}
* @param end {int}
* @return {bool} false key
* key true
*/
bool ltrim(const char* key, int start, int end);
/**
*
* @param key {const char*} key
* @param buf {string&}
* @return {int} 1 -- -1 --
*
*/
int rpop(const char* key, string& buf);
/**
*
* src ()
* src dst dst
* @param src {const char*} key
* @param dst {const char*} key
* @param buf {string*} src key
* @return {bool} src dst
* true false src/dst
*/
bool rpoplpush(const char* src, const char* dst, string* buf = NULL);
/**
* key
* @param key {const char*} key
* @param first_value {const char*}
* NULL
* @return {int} -1 key
* key
*/
int rpush(const char* key, const char* first_value, ...);
int rpush(const char* key, const char* values[], size_t argc);
int rpush(const char* key, const std::vector<string>& values);
int rpush(const char* key, const std::vector<const char*>& values);
int rpush(const char* key, const char* values[], size_t lens[],
size_t argc);
/**
*
*
* @param key {const char*} key
* @param value {const char*}
* @return {int}
* -1 key
* 0 key
* >0
*/
int rpushx(const char* key, const char* value);
int rpushx(const char* key, const char* value, size_t len);
private:
int linsert(const char* key, const char* pos, const char* pivot,

View File

@ -20,32 +20,77 @@ public:
/////////////////////////////////////////////////////////////////////
/**
*
* channel
* @param channel {const char*}
* @param msg {const char*}
* @param len {size_t}
* @return {int}
* -1
* 0
* > 0
* 0
* >0
*/
int publish(const char* channel, const char* msg, size_t len);
/**
*
* subscribeunsubscribepsubscribepunsubscribeget_message
*
* @param first_channel {const char*}
* NULL
* @return {int}
*/
int subscribe(const char* first_channel, ...);
int subscribe(const std::vector<const char*>& channels);
int subscribe(const std::vector<string>& channels);
/**
*
* @param first_channel {const char*}
* @return {int}
*/
int unsubscribe(const char* first_channel, ...);
int unsubscribe(const std::vector<const char*>& channels);
int unsubscribe(const std::vector<string>& channels);
/**
* *
*
* subscribeunsubscribepsubscribepunsubscribeget_message
*
* @param first_pattern {const char*}
* @return {int}
*/
int psubscribe(const char* first_pattern, ...);
int psubscribe(const std::vector<const char*>& patterns);
int psubscribe(const std::vector<string>& patterns);
/**
*
* @param first_pattern {const char*}
* @return {int}
*/
int punsubscribe(const char* first_pattern, ...);
int punsubscribe(const std::vector<const char*>& patterns);
int punsubscribe(const std::vector<string>& patterns);
/**
* subscribe
* psubscribe
* @param channel {string&}
* @param msg {string&}
* @return {bool} false
*/
bool get_message(string& channel, string& msg);
/**
*
*
* @param channels {std::vector<string>&}
* @param first_pattern {const char*}
* NULL NULL
* @return {int} -1
*
*/
int pubsub_channels(std::vector<string>& channels,
const char* first_pattern, ...);
int pubsub_channels(const std::vector<const char*>& patterns,
@ -53,6 +98,14 @@ public:
int pubsub_channels(const std::vector<string>& patterns,
std::vector<string>& channels);
/**
*
* @param out {std::map<string, int>&} out->first
* out->second
* @param first_pattern {const char*}
* NULL NULL
* @return {int} -1
*/
int pubsub_numsub(std::map<string, int>& out,
const char* first_channel, ...);
int pubsub_numsub(const std::vector<const char*>& channels,
@ -60,6 +113,11 @@ public:
int pubsub_numsub(const std::vector<string>& channels,
std::map<string, int>& out);
/**
*
*
* @return {int} -1
*/
int pubsub_numpat();
private:

View File

@ -17,6 +17,15 @@ public:
/////////////////////////////////////////////////////////////////////
/**
* member key member
* ;
* 1) key member
* 2) key
* @param key {const char*}
* @param first_member {const char*} NULL
* @return {int}
*/
int sadd(const char* key, const char* first_member, ...);
int sadd(const char* key, const std::vector<const char*>& memsbers);
int sadd(const char* key, const std::vector<string>& members);
@ -24,58 +33,159 @@ public:
int sadd(const char* key, const char* argv[], const size_t lens[],
size_t argc);
/**
*
* @param key {const char*}
* @param buf {string&}
* @return {bool} key key false
*/
bool spop(const char* key, string& buf);
/**
*
* @param key {const char*}
* @return {int}
* -1
* 0 key
* >0
*/
int scard(const char* key);
/**
* key
* @param key {const char*}
* @param members {std::vector<string>&}
* @return {int} -1 key
*/
int smembers(const char* key, std::vector<string>& members);
/**
* member src dst
* @param src {const char*}
* @param dst {const char*}
* @param member {const char*}
* @return {int}
* -1/
* 0
* 1
*/
int smove(const char* src, const char* dst, const char* member);
int smove(const char* src, const char* dst, const string& member);
int smove(const char* src, const char* dst,
const char* member, size_t len);
/**
*
* @param members {std::vector<string>&}
* @param first_key {const char*} key
* @return {int} -1 key
*/
int sdiff(std::vector<string>& members, const char* first_key, ...);
int sdiff(const std::vector<const char*>& keys,
std::vector<string>& members);
int sdiff(const std::vector<string>& keys,
std::vector<string>& members);
/**
*
* @param members {std::vector<string>&}
* @param first_key {const char*} keyNULL
* @return {int} -1 key
*/
int sinter(std::vector<string>& members, const char* first_key, ...);
int sinter(const std::vector<const char*>& keys,
std::vector<string>& members);
int sinter(const std::vector<string>& keys,
std::vector<string>& members);
/**
*
* @param members {std::vector<string>&}
* @param first_key {const char*} keyNULL
* @return {int} -1 key
*/
int sunion(std::vector<string>& members, const char* first_key, ...);
int sunion(const std::vector<const char*>& keys,
std::vector<string>& members);
int sunion(const std::vector<string>& keys,
std::vector<string>& members);
/**
* SDIFF dst
* @param dst {const char*}
* @param first_key {const char*}
* @return {int}
*/
int sdiffstore(const char* dst, const char* first_key, ...);
int sdiffstore(const char* dst, const std::vector<const char*>& keys);
int sdiffstore(const char* dst, const std::vector<string>& keys);
/**
* SINTER dst
* @param dst {const char*}
* @param first_key {const char*}
* @return {int}
*/
int sinterstore(const char* dst, const char* first_key, ...);
int sinterstore(const char* dst, const std::vector<const char*>& keys);
int sinterstore(const char* dst, const std::vector<string>& keys);
/**
* SUNION dst
* @param dst {const char*}
* @param first_key {const char*}
* @return {int}
*/
int sunionstore(const char* dst, const char* first_key, ...);
int sunionstore(const char* dst, const std::vector<const char*>& keys);
int sunionstore(const char* dst, const std::vector<string>& keys);
/**
* member key
* @param key {const char*}
* @param member {const char*}
* @return {bool} true key
*
*/
bool sismember(const char* key, const char* member);
bool sismember(const char* key, const char* member, size_t len);
/**
* key
*
* @param key {const char*}
* @param out
* @return {int} -1 0
*/
int srandmember(const char* key, string& out);
int srandmember(const char* key, size_t n, std::vector<string>& out);
int srem(const char* key, const char* member);
int srem(const char* key, const char* member, size_t len);
/**
* key member member
* @param key {const char*}
* @param first_member {const char*} NULL成员
* NULL
* @retur {int} -1 key
* 0
*/
int srem(const char* key, const char* first_member, ...);
int srem(const char* key, const std::vector<string>& members);
int srem(const char* key, const std::vector<const char*>& members);
int srem(const char* key, const char* members[],
size_t lens[], size_t argc);
/**
*
* @param key {const char*}
* @param cursor {int} 0
* @param out {std::vector<string>&}
* @param pattern {const char*} glob
* @param count {const size_t*}
* @return {int}
* 0
* -1:
* >0:
*/
int sscan(const char* key, int cursor, std::vector<string>& out,
const char* pattern = NULL, const size_t* count = NULL);
};

View File

@ -11,6 +11,9 @@ class string;
class redis_client;
class redis_result;
/**
* PSETEX
*/
class ACL_CPP_API redis_string : public redis_command
{
public:
@ -19,74 +22,203 @@ public:
/////////////////////////////////////////////////////////////////////
/**
* value key
* @param key {const char*} key
* @param value {const char*} value
* @return {bool} false key
*/
bool set(const char* key, const char* value);
bool set(const char* key, size_t key_len,
const char* value, size_t value_len);
/**
* value key key seconds ()
* key SETEX
* @param key {const char*} key
* @param value {const char*} value
* @param timeout {int}
* @return {bool} false key
*/
bool setex(const char* key, const char* value, int timeout);
bool setex(const char* key, size_t key_len, const char* value,
size_t value_len, int timeout);
/**
* key value key key
* SETNX
* @param key {const char*} key
* @param value {const char*} value
* @return {int}
* -1 key
* 0 key
* 1
*/
int setnx(const char* key, const char* value);
int setnx(const char* key, size_t key_len,
const char* value, size_t value_len);
/**
* key APPEND value key
* key APPEND key value
* @param key {const char*} key
* @param value {const char*}
* @return {int} -1 key
*/
int append(const char* key, const char* value);
int append(const char* key, const char* value, size_t size);
/**
* key
* @param key {const char*} key
* @param buf {string&}
* @return {bool} false key
*/
bool get(const char* key, string& buf);
bool get(const char* key, size_t len, string& buf);
/**
* key
* 使
* redis_result::get(size_t, size_t*)
* redis_result::get_size()
* @param key {const char*} key
* @param buf {string&}
* @return {bool} false key
*/
const redis_result* get(const char* key);
const redis_result* get(const char* key, size_t len);
/**
* key value key key
*
* @param key {const char*} key
* @param value {const char*}
* @param buf {string&}
* @return {bool}
*/
bool getset(const char* key, const char* value, string& buf);
bool getset(const char* key, size_t key_len,
const char* value, size_t value_len, string& buf);
bool getset(const char* key, size_t key_len, const char* value,
size_t value_len, string& buf);
/////////////////////////////////////////////////////////////////////
int str_len(const char* key);
int str_len(const char* key, size_t len);
/**
* key
* @param key {const char*} key
* @return {int}
* -1
* 0 key
* >0
*/
int get_strlen(const char* key);
int get_strlen(const char* key, size_t len);
/**
* value (overwrite) key offset
* key
* @param key {const char*} key
* @param offset {unsigned}
* \0
* @param value {const char*}
* @return {int}
*/
int setrange(const char* key, unsigned offset, const char* value);
int setrange(const char* key, size_t key_len, unsigned offset,
const char* value, size_t value_len);
/**
* key start end
* ( start end )
* @param key {const char*} key
* @param start {int}
* @param end {int}
* @param buf {string&}
* @return {bool}
* -1
*/
bool getrange(const char* key, int start, int end, string& buf);
bool getrange(const char* key, size_t key_len,
int start, int end, string& buf);
/////////////////////////////////////////////////////////////////////
bool setbit(const char* key, unsigned offset, int bit);
bool setbit(const char* key, size_t len, unsigned offset, int bit);
/**
* key (bit)
* value 0 1
* @param key {const char*} key
* @param offset {unsigned}
* @param bit {bool} true
* @return {int}
* -1 key
* 0 0
* 1 1
*/
bool setbit(const char* key, unsigned offset, bool bit);
bool setbit(const char* key, size_t len, unsigned offset, bool bit);
/**
* key (bit) offset
* key 0
* @param key {const char*} key
* @param offset {unsigned}
* @param bit {int&}
* @return {bool} false key
*/
bool getbit(const char* key, unsigned offset, int& bit);
bool getbit(const char* key, size_t len, unsigned offset, int& bit);
/**
* 1 start/end
*
* @param key {const char*} key
* @return {int} 1 -1
*/
int bitcount(const char* key);
int bitcount(const char* key, size_t len);
int bitcount(const char* key, int start, int end);
int bitcount(const char* key, size_t len, int start, int end);
/**
* key destkey
* @param destkey {const char*} key
* @param keys
* @return {int}
*/
int bitop_and(const char* destkey, const std::vector<string>& keys);
int bitop_or(const char* destkey, const std::vector<string>& keys);
int bitop_xor(const char* destkey, const std::vector<string>& keys);
int bitop_and(const char* destkey, const std::vector<const char*>& keys);
int bitop_or(const char* destkey, const std::vector<const char*>& keys);
int bitop_xor(const char* destkey, const std::vector<const char*>& keys);
int bitop_and(const char* destkey, const char* key, ...);
int bitop_or(const char* destkey, const char* key, ...);
int bitop_xor(const char* destkey, const char* key, ...);
int bitop_and(const char* destkey, const char* keys[], size_t size);
/**
* key destkey
* @param destkey {const char*} key
* @param keys
* @return {int}
*/
int bitop_or(const char* destkey, const std::vector<string>& keys);
int bitop_or(const char* destkey, const std::vector<const char*>& keys);
int bitop_or(const char* destkey, const char* key, ...);
int bitop_or(const char* destkey, const char* keys[], size_t size);
/**
* key destkey
* @param destkey {const char*} key
* @param keys
* @return {int}
*/
int bitop_xor(const char* destkey, const std::vector<string>& keys);
int bitop_xor(const char* destkey, const std::vector<const char*>& keys);
int bitop_xor(const char* destkey, const char* key, ...);
int bitop_xor(const char* destkey, const char* keys[], size_t size);
/////////////////////////////////////////////////////////////////////
/**
* key-value
* @param objs key-value
* @return {bool}
*/
bool mset(const std::map<string, string>& objs);
bool mset(const std::map<int, string>& objs);
@ -101,6 +233,14 @@ public:
/////////////////////////////////////////////////////////////////////
/**
* key key-value
* @param objs key-value
* @return {int}
* -1
* 0 key
* 1
*/
int msetnx(const std::map<string, string>& objs);
int msetnx(const std::map<int, string>& objs);
@ -115,6 +255,14 @@ public:
/////////////////////////////////////////////////////////////////////
/**
* () key key key
* key
* @param keys {const std::vector<string>&} key
* @param out {std::vector<string>*}
* key
* @return {bool}
*/
bool mget(const std::vector<string>& keys,
std::vector<string>* out = NULL);
bool mget(const std::vector<const char*>& keys,
@ -131,26 +279,91 @@ public:
bool mget(const char* keys[], const size_t keys_len[], size_t argc,
std::vector<string>* out = NULL);
/**
* mget
* @return {size_t}
*/
size_t mget_size() const;
/**
* NULL
* mget_size()
* @param i {size_t}
* @param len {size*}
* @return {const char*}
*/
const char* mget_value(size_t i, size_t* len = NULL) const;
/**
* mget_size()
* @param i {size_t}
* @return {const redis_result*} NULL
*/
const redis_result* mget_child(size_t i) const;
/////////////////////////////////////////////////////////////////////
/**
* key
* 1 key key 0 INCR
* 2
* 3 64 (bit)
* @param key {const char*} key
* @param result {long long int*}
* @return {bool}
*/
bool incr(const char* key, long long int* result = NULL);
/**
* key increment
* 1 key key 0 INCRBY
* 2
* 3 64 (bit)
* @param key {const char*} key
* @param inc {long long int}
* @param result {long long int*}
* @return {bool}
*/
bool incrby(const char* key, long long int inc,
long long int* result = NULL);
/**
* key
* 1) key INCRBYFLOAT key 0
* 2) key
*
* 3)
* @param key {const char*} key
* @param inc {double}
* @param result {double*}
* @return {bool}
*/
bool incrbyfloat(const char* key, double inc, double* result = NULL);
/**
* key
* 1) key key 0 DECR
* 2)
* 3) 64 (bit)
* @param key {const char*} key
* @param result {long long int*}
* @return {bool}
*/
bool decr(const char* key, long long int* result = NULL);
/**
* key decrement
* 1) key key 0 DECRBY
* 2)
* 3) 64 (bit)
* @param key {const char*} key
* @param dec {long long int}
* @param result {long long int*}
* @return {bool}
*/
bool decrby(const char* key, long long int dec,
long long int* result = NULL);
bool incoper(const char* cmd, const char* key, long long int inc,
long long int* result);
/////////////////////////////////////////////////////////////////////
private:
int bitop(const char* op, const char* destkey,
const std::vector<string>& keys);
@ -158,6 +371,10 @@ private:
const std::vector<const char*>& keys);
int bitop(const char* op, const char* destkey,
const char* keys[], size_t size);
bool incoper(const char* cmd, const char* key, long long int inc,
long long int* result);
};
} // namespace acl

View File

@ -18,15 +18,67 @@ public:
/////////////////////////////////////////////////////////////////////
/**
* () key () key
*
* @param keys {const std::vector<string>&} key
* @return {bool} 使 key key
*/
bool watch(const std::vector<string>& keys);
bool unwatch(const std::vector<string>& keys);
/**
* WATCH key
* @return {bool}
*/
bool unwatch();
/**
*
* EXEC (atomic)
* @return {bool}
*/
bool multi();
/**
* () key WATCH
* () key EXEC ()
* key (abort)
* get_size()/get_child()
*
* @return {bool}
*/
bool exec();
/**
* 使 WATCH ()
* key UNWATCH
*/
bool discard();
/**
* multi exec redis
* @param cmd {const char*} redis
* @param argv {const char* []}
* @param lens [const size_t []}
* @param argc {size_t}
* @return {bool}
*/
bool queue_cmd(const char* cmd, const char* argv[],
const size_t lens[], size_t argc);
/**
* exec
* @return {size_t}
*/
size_t get_size() const;
/**
*
* @param i {size_t}
* @param cmd {string*} redis
* @return {const redis_result*}
* i NULL
*/
const redis_result* get_child(size_t i, string* cmd) const;
private:

View File

@ -141,7 +141,7 @@ static void test_strlen(acl::redis_string& option, int n)
key.format("%s_%d", __keypre.c_str(), i);
option.reset();
int ret = option.str_len(key.c_str());
int ret = option.get_strlen(key.c_str());
if (ret < 0)
{
printf("str_len error, key: %s\r\n", key.c_str());

View File

@ -39,12 +39,8 @@ int redis_list::llen(const char* key)
return conn_->get_number();
}
bool redis_list::lindex(const char* key, size_t idx,
string& buf, bool* exist /* = NULL */)
bool redis_list::lindex(const char* key, size_t idx, string& buf)
{
if (exist)
*exist = false;
const char* argv[3];
size_t lens[3];
@ -59,19 +55,15 @@ bool redis_list::lindex(const char* key, size_t idx,
lens[2] = strlen(tmp);
conn_->build_request(3, argv, lens);
long ret = conn_->get_string(buf);
if (exist && ret > 0)
*exist = true;
return ret >= 0 ? true : false;
return conn_->get_string(buf) >= 0 ? true : false;
}
bool redis_list::lset(const char* key, size_t idx, const char* value)
bool redis_list::lset(const char* key, int idx, const char* value)
{
return lset(key, idx, value, strlen(value));
}
bool redis_list::lset(const char* key, size_t idx,
const char* value, size_t len)
bool redis_list::lset(const char* key, int idx, const char* value, size_t len)
{
const char* argv[4];
size_t lens[4];
@ -469,7 +461,7 @@ bool redis_list::brpoplpush(const char* src, const char* dst,
return conn_->get_string(buf) >= 0 ? true : false;
}
bool redis_list::lrange(const char* key, size_t start, size_t end,
bool redis_list::lrange(const char* key, int start, int end,
std::vector<string>& result)
{
const char* argv[4];
@ -481,8 +473,8 @@ bool redis_list::lrange(const char* key, size_t start, size_t end,
lens[1] = strlen(key);
char start_s[LONG_LEN], end_s[LONG_LEN];
safe_snprintf(start_s, sizeof(start_s), "%lu", (unsigned long) start);
safe_snprintf(end_s, sizeof(end_s), "%lu", (unsigned long) end);
safe_snprintf(start_s, sizeof(start_s), "%d", start);
safe_snprintf(end_s, sizeof(end_s), "%d", end);
argv[2] = start_s;
lens[2] = strlen(start_s);
@ -520,7 +512,7 @@ int redis_list::lrem(const char* key, int count, const char* value, size_t len)
return conn_->get_number();
}
bool redis_list::ltrim(const char* key, size_t start, size_t end)
bool redis_list::ltrim(const char* key, int start, int end)
{
const char* argv[4];
size_t lens[4];
@ -531,8 +523,8 @@ bool redis_list::ltrim(const char* key, size_t start, size_t end)
lens[1] = strlen(key);
char start_s[LONG_LEN], end_s[LONG_LEN];
safe_snprintf(start_s, sizeof(start_s), "%lu", (unsigned long) start);
safe_snprintf(end_s, sizeof(end_s), "%lu", (unsigned long) end);
safe_snprintf(start_s, sizeof(start_s), "%d", start);
safe_snprintf(end_s, sizeof(end_s), "%d", end);
argv[2] = start_s;
lens[2] = strlen(start_s);

View File

@ -351,29 +351,6 @@ int redis_set::srandmember(const char* key, size_t n, std::vector<string>& out)
return conn_->get_strings(out);
}
int redis_set::srem(const char* key, const char* member)
{
return srem(key, member, strlen(member));
}
int redis_set::srem(const char* key, const char* member, size_t len)
{
const char* argv[3];
size_t lens[3];
argv[0] = "SREM";
lens[0] = sizeof("SREM") - 1;
argv[1] = key;
lens[1] = strlen(key);
argv[2] = member;
lens[2] = len;
conn_->build_request(3, argv, lens);
return conn_->get_number();
}
int redis_set::srem(const char* key, const char* first_member, ...)
{
std::vector<const char*> members;

View File

@ -184,12 +184,12 @@ bool redis_string::getset(const char* key, size_t key_len,
/////////////////////////////////////////////////////////////////////////////
int redis_string::str_len(const char* key)
int redis_string::get_strlen(const char* key)
{
return str_len(key, strlen(key));
return get_strlen(key, strlen(key));
}
int redis_string::str_len(const char* key, size_t len)
int redis_string::get_strlen(const char* key, size_t len)
{
const char* argv[2];
size_t lens[2];
@ -262,12 +262,13 @@ bool redis_string::getrange(const char* key, size_t key_len,
/////////////////////////////////////////////////////////////////////////////
bool redis_string::setbit(const char* key, unsigned offset, int bit)
bool redis_string::setbit(const char* key, unsigned offset, bool bit)
{
return setbit(key, strlen(key), offset, bit);
}
bool redis_string::setbit(const char* key, size_t len, unsigned offset, int bit)
bool redis_string::setbit(const char* key, size_t len,
unsigned offset, bool bit)
{
const char* argv[4];
size_t lens[4];

View File

@ -24,14 +24,19 @@ bool redis_transaction::watch(const std::vector<string>& keys)
return conn_->get_status();
}
bool redis_transaction::unwatch(const std::vector<string>& keys)
bool redis_transaction::unwatch()
{
conn_->build("UNWATCH", NULL, keys);
const char* argv[1];
size_t lens[1];
conn_->build_request(1, argv, lens);
return conn_->get_status();
}
bool redis_transaction::multi()
{
cmds_.clear();
const char* argv[1];
size_t lens[1];