Skip to content

Commit 6ec4740

Browse files
committed
add comments for redis_set
1 parent 0354fce commit 6ec4740

File tree

1 file changed

+153
-11
lines changed

1 file changed

+153
-11
lines changed

lib_acl_cpp/include/acl_cpp/redis/redis_set.hpp

+153-11
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,19 @@ class ACL_CPP_API redis_set : virtual public redis_command
3636
* 将被忽略;
3737
* 1) 假如 key 不存在,则创建一个只包含 member 元素作成员的集合
3838
* 2) 当 key 不是集合类型时,返回一个错误
39+
* add one or more members to a set stored at a key
40+
* 1) if the key doesn't exist, a new set by the key will be created,
41+
* and add the members to the set
42+
* 2) if the key exists and not a set's key, then error happened
3943
* @param key {const char*} 集合对象的键
44+
* the key of a set
4045
* @param first_member {const char*} 第一个非 NULL 的成员
46+
* the first member of a variable args which isn't NULL, the last
47+
* arg of the args must be NULL indicating the end of args
4148
* @return {int} 被添加到集合中的新元素的数量,不包括被忽略的元素
49+
* the number of elements that were added to the set, not including
50+
* all the elements already present into the set. -1 if error
51+
* happened or it isn't a set stored by the key.
4252
*/
4353
int sadd(const char* key, const char* first_member, ...);
4454
int sadd(const char* key, const std::vector<const char*>& memsbers);
@@ -49,49 +59,93 @@ class ACL_CPP_API redis_set : virtual public redis_command
4959

5060
/**
5161
* 从集合对象中随机移除并返回某个成员
62+
* remove and get one member from the set
5263
* @param key {const char*} 集合对象的键
64+
* the key of the set
5365
* @param buf {string&} 存储被移除的成员
66+
* store the member removed from the set
5467
* @return {bool} 当 key 不存在或 key 是空集时返回 false
68+
* true if one member has been removed and got, false if the key
69+
* doesn't exist or it isn't a set stored at the key.
5570
*/
5671
bool spop(const char* key, string& buf);
5772

5873
/**
5974
* 获得集合对象中成员的数量
75+
* get the number of members in a set stored at the key
6076
* @param key {const char*} 集合对象的键
77+
* the key of the set
6178
* @return {int} 返回该集合对象中成员数量,含义如下:
79+
* return int value as below:
6280
* -1:出错或非集合对象
81+
* error or it's not a set by the key
6382
* 0:成员数量为空或该 key 不存在
83+
* the set is empty or the key doesn't exist
6484
* >0:成员数量非空
85+
* the number of members in the set
6586
*/
6687
int scard(const char* key);
6788

6889
/**
6990
* 返回集合 key 中的所有成员
91+
* get all the members in a set stored at a key
7092
* @param key {const char*} 集合对象的键值
93+
* the key of the set
7194
* @param members {std::vector<string>*} 非空时存储结果集
95+
* if not NULL, it will store the members.
7296
* @return {int} 结果集数量,返回 -1 表示出错或有一个 key 非集合对象
97+
* the number of elements got, -1 if error happened or it't not
98+
* a set by the key.
99+
*
73100
* 操作成功后可以通过以下任一方式获得数据
74-
* 1、基类方法 get_value 获得指定下标的元素数据
75-
* 2、基类方法 get_child 获得指定下标的元素对象(redis_result),然后再通过
101+
* if successul, one of below ways can be used to get the result:
102+
* 1、在调用方法中传入非空的存储结果对象的地址
103+
* input the no-NULL result parameter when call hmget, when
104+
* success, the result will store the values of the given fileds
105+
*
106+
* 2、基类方法 get_value 获得指定下标的元素数据
107+
* call redis_command::result_value with the specified subscript
108+
*
109+
* 3、基类方法 get_child 获得指定下标的元素对象(redis_result),然后再通过
76110
* redis_result::argv_to_string 方法获得元素数据
77-
* 3、基类方法 get_result 方法取得总结果集对象 redis_result,然后再通过
111+
* call redis_command::result_child with specified subscript to
112+
* get redis_result object, then call redis_result::argv_to_string
113+
* with above result to get the values of the give fileds
114+
*
115+
* 4、基类方法 get_result 方法取得总结果集对象 redis_result,然后再通过
78116
* redis_result::get_child 获得一个元素对象,然后再通过方式 2 中指定
79117
* 的方法获得该元素的数据
80-
* 4、基类方法 get_children 获得结果元素数组对象,再通过 redis_result 中
118+
* call redis_command::get_result with the specified subscript to
119+
* get redis_result object, and use redis_result::get_child to
120+
* get one result object, then call redis_result::argv_to_string
121+
* to get the value of one filed.
122+
*
123+
* 5、基类方法 get_children 获得结果元素数组对象,再通过 redis_result 中
81124
* 的方法 argv_to_string 从每一个元素对象中获得元素数据
82-
* 5、在调用方法中传入非空的存储结果对象的地址
125+
* use redis_command::get_children to get the redis_result array,
126+
* then use redis_result::argv_to_string to get every value of
127+
* the given fileds
83128
*/
84129
int smembers(const char* key, std::vector<string>* members);
85130

86131
/**
87132
* 将 member 元素从 src 集合移动到 dst 集合
133+
* move a member from one set to another
88134
* @param src {const char*} 源集合对象的键值
135+
* the source key of a set
89136
* @param dst {const char*} 目标集合对象的键值
137+
* the destination key of a set
90138
* @param member {const char*} 源集合对象的成员
139+
* the member in the source set
91140
* @return {int} 返回值含义如下:
141+
* return int value as below:
92142
* -1:出错或源/目标对象有一个非集合对象
143+
* error happened, or one of source and destination isn't a set
93144
* 0:源对象不存在或成员在源对象中不存在
145+
* the source set or the member doesn't exist
94146
* 1:成功从源对象中将一个成员移动至目标对象中
147+
* move successfully the member from source set to
148+
* the destination set
95149
*/
96150
int smove(const char* src, const char* dst, const char* member);
97151
int smove(const char* src, const char* dst, const string& member);
@@ -100,19 +154,45 @@ class ACL_CPP_API redis_set : virtual public redis_command
100154

101155
/**
102156
* 返回一个集合的全部成员,该集合是所有给定集合之间的差集
157+
* return the members of the set resulting from the difference
158+
* between the first set and all the successive sets.
103159
* @param members {std::vector<string>*} 非空时存储结果集
160+
* if not NULL, it will store the members.
104161
* @param first_key {const char*} 第一个非空的集合对象 key
162+
* the key of the first set in a variable sets list, the last one
163+
* must be NULL indicating the end of the sets list.
105164
* @return {int} 结果集数量,返回 -1 表示出错或有一个 key 非集合对象
165+
* the number of elements got, -1 if error happened or it't not
166+
* a set by the key.
106167
* 操作成功后可以通过以下任一方式获得数据
107-
* 1、基类方法 get_value 获得指定下标的元素数据
108-
* 2、基类方法 get_child 获得指定下标的元素对象(redis_result),然后再通过
168+
* if successul, one of below ways can be used to get the result:
169+
* 1、在调用方法中传入非空的存储结果对象的地址
170+
* input the no-NULL result parameter when call hmget, when
171+
* success, the result will store the values of the given fileds
172+
*
173+
* 2、基类方法 get_value 获得指定下标的元素数据
174+
* call redis_command::result_value with the specified subscript
175+
*
176+
* 3、基类方法 get_child 获得指定下标的元素对象(redis_result),然后再通过
109177
* redis_result::argv_to_string 方法获得元素数据
110-
* 3、基类方法 get_result 方法取得总结果集对象 redis_result,然后再通过
178+
* call redis_command::result_child with specified subscript to
179+
* get redis_result object, then call redis_result::argv_to_string
180+
* with above result to get the values of the give fileds
181+
*
182+
* 4、基类方法 get_result 方法取得总结果集对象 redis_result,然后再通过
111183
* redis_result::get_child 获得一个元素对象,然后再通过方式 2 中指定
112184
* 的方法获得该元素的数据
113-
* 4、基类方法 get_children 获得结果元素数组对象,再通过 redis_result 中
185+
* call redis_command::get_result with the specified subscript to
186+
* get redis_result object, and use redis_result::get_child to
187+
* get one result object, then call redis_result::argv_to_string
188+
* to get the value of one filed.
189+
*
190+
* 5、基类方法 get_children 获得结果元素数组对象,再通过 redis_result 中
114191
* 的方法 argv_to_string 从每一个元素对象中获得元素数据
115-
* 5、在调用方法中传入非空的存储结果对象的地址
192+
* use redis_command::get_children to get the redis_result array,
193+
* then use redis_result::argv_to_string to get every value of
194+
* the given fileds
195+
116196
*/
117197
int sdiff(std::vector<string>* members, const char* first_key, ...);
118198
int sdiff(const std::vector<const char*>& keys,
@@ -122,9 +202,16 @@ class ACL_CPP_API redis_set : virtual public redis_command
122202

123203
/**
124204
* 返回一个集合的全部成员,该集合是所有给定集合的交集
205+
* return the members of a set resulting from the intersection of
206+
* all the give sets.
125207
* @param members {std::vector<string>*} 非空时存储结果集
208+
* if not NULL, it will store the result
126209
* @param first_key {const char*} 第一个集合对象 key(非NULL)
210+
* the key of the first set in a variable set list, which isn't NULL,
211+
* the last one must be NULL in the set list.
127212
* @return {int} 结果集数量,返回 -1 表示出错或有一个 key 非集合对象
213+
* return the number of the members, -1 if error happened or
214+
* it't not a set by the key.
128215
*/
129216
int sinter(std::vector<string>* members, const char* first_key, ...);
130217
int sinter(const std::vector<const char*>& keys,
@@ -134,9 +221,16 @@ class ACL_CPP_API redis_set : virtual public redis_command
134221

135222
/**
136223
* 返回一个集合的全部成员,该集合是所有给定集合的并集
224+
* return the members of a set resulting from the union of all the
225+
* given sets.
137226
* @param members {std::vector<string>*} 非空时存储结果集
227+
* if not NULL, it will store the result
138228
* @param first_key {const char*} 第一个集合对象 key(非NULL)
229+
* the key of the first set in a variable set list, which isn't NULL,
230+
* and the last arg must be NULL indicating the end of the set list.
139231
* @return {int} 结果集数量,返回 -1 表示出错或有一个 key 非集合对象
232+
* return the number of members, -1 if error happened or it's not
233+
* a set by the key.
140234
*/
141235
int sunion(std::vector<string>* members, const char* first_key, ...);
142236
int sunion(const std::vector<const char*>& keys,
@@ -146,61 +240,99 @@ class ACL_CPP_API redis_set : virtual public redis_command
146240

147241
/**
148242
* 这个命令的作用和 SDIFF 类似,但它将结果保存到 dst 集合,而不是简单地返回结果集
243+
* This command is equal to SDIFF, but instead of returning
244+
* the resulting set, it is stored in destination.
149245
* @param dst {const char*} 目标集合对象键值
246+
* the key of the destination set
150247
* @param first_key {const char*} 第一个非空的集合对象键值
248+
* the key of the first set in a variable set list, which isn't NULL,
249+
* and the last arg must be NULL indicating the end of the set list.
151250
* @return {int} 结果集中的成员数量
251+
* return the number of members, -1 if error happened or it's not
252+
* a set by the key.
152253
*/
153254
int sdiffstore(const char* dst, const char* first_key, ...);
154255
int sdiffstore(const char* dst, const std::vector<const char*>& keys);
155256
int sdiffstore(const char* dst, const std::vector<string>& keys);
156257

157258
/**
158259
* 这个命令类似于 SINTER 命令,但它将结果保存到 dst 集合,而不是简单地返回结果集
260+
* This command is equal to SINTER, but instead of returning
261+
* the resulting set, it is stored in destination.
159262
* @param dst {const char*} 目标集合对象键值
263+
* the key of the destination set
160264
* @param first_key {const char*} 第一个非空的集合对象键值
265+
* the key of the first set in a variable set list, which isn't NULL,
266+
* and the last arg must be NULL indicating the end of the set list.
161267
* @return {int} 结果集中的成员数量
268+
* return the number of members, -1 if error happened or it's not
269+
* a set by the key.
162270
*/
163271
int sinterstore(const char* dst, const char* first_key, ...);
164272
int sinterstore(const char* dst, const std::vector<const char*>& keys);
165273
int sinterstore(const char* dst, const std::vector<string>& keys);
166274

167275
/**
168276
* 这个命令类似于 SUNION 命令,但它将结果保存到 dst 集合,而不是简单地返回结果集
277+
* This command is equal to SUNION, but instead of returning
278+
* the resulting set, it is stored in destination.
169279
* @param dst {const char*} 目标集合对象键值
280+
* the key of the destination set
170281
* @param first_key {const char*} 第一个非空的集合对象键值
282+
* the key of the first set in a variable set list, which isn't NULL,
283+
* and the last arg must be NULL indicating the end of the set list.
171284
* @return {int} 结果集中的成员数量
285+
* return the number of members, -1 if error happened or it's not
286+
* a set by the key.
172287
*/
173288
int sunionstore(const char* dst, const char* first_key, ...);
174289
int sunionstore(const char* dst, const std::vector<const char*>& keys);
175290
int sunionstore(const char* dst, const std::vector<string>& keys);
176291

177292
/**
178293
* 判断 member 元素是否集合 key 的成员
294+
* determine if a given value is a member of a set
179295
* @param key {const char*} 集合对象的键值
180-
* @param member {const char*} 集合对象中的一个成员元素
296+
* the key of a set
297+
* @param member {const char*} 给定值
298+
* the given value
181299
* @return {bool} 返回 true 表示是,否则可能是因为不是或出错或该 key 对象
182300
* 非集合对象
301+
* true if the given is a member of the set, false if it's not a
302+
* member of the set, or error, or it's not a set by the key.
183303
*/
184304
bool sismember(const char* key, const char* member);
185305
bool sismember(const char* key, const char* member, size_t len);
186306

187307
/**
188308
* 如果命令执行时,只提供了 key 参数,那么返回集合中的一个随机元素,如果还同时指定
189309
* 了元素个数,则会返回一个不超过该个数限制的结果集
310+
* get one or multiple memebers from a set
190311
* @param key {const char*} 集合对象的键值
312+
* the key of a set
191313
* @param out 存储结果或结果集
314+
* store the result
192315
* @return {int} 结果的个数,为 -1 表示出错,0 表示没有成员
316+
* the number of members, 0 if the set by the key is empty,
317+
* -1 if error happened.
193318
*/
194319
int srandmember(const char* key, string& out);
195320
int srandmember(const char* key, size_t n, std::vector<string>& out);
196321

197322
/**
198323
* 移除集合 key 中的一个或多个 member 元素,不存在的 member 元素会被忽略
324+
* Remove the specified members from the set stored at key. if the
325+
* member doesn't exist, it will be ignored.
199326
* @param key {const char*} 集合对象的键值
327+
* the key of the set
200328
* @param first_member {const char*} 需要被移除的成员列表的第一个非 NULL成员,
201329
* 在变参的输入中需要将最后一个变参写 NULL
330+
* the first non-NULL member to be removed in a variable member list,
331+
* and the last one must be NULL indicating the end of the list.
202332
* @retur {int} 被移除的成员元素的个数,当出错或非集合对象时返回 -1;当 key 不
203333
* 存在或成员不存在时返回 0
334+
* the number of members be removed, 0 if the set is empty or the
335+
* key doesn't exist, -1 if error happened or it's not a set by key
204336
*/
205337
int srem(const char* key, const char* first_member, ...);
206338
int srem(const char* key, const std::vector<string>& members);
@@ -210,17 +342,27 @@ class ACL_CPP_API redis_set : virtual public redis_command
210342

211343
/**
212344
* 命令用于迭代当前数据库中的数据库键
345+
* scan the members in a set stored at key
213346
* @param key {const char*} 哈希键值
347+
* the key of a set
214348
* @param cursor {int} 游标值,开始遍历时该值写 0
349+
* the cursor value, which is 0 at begin
215350
* @param out {std::vector<string>&} 存储结果集,内部以追加方式将本次遍历
216351
* 结果集合添加进该数组中,为防止因总结果集过大导致该数组溢出,用户可在调用本
217352
* 函数前后清理该数组对象
353+
* store result in appending mode.
218354
* @param pattern {const char*} 匹配模式,glob 风格,非空时有效
355+
* match pattern, effective only on no-NULL
219356
* @param count {const size_t*} 限定的结果集数量,非空指针时有效
357+
* the max count of one scan process, effective only on no-NULL
220358
* @return {int} 下一个游标位置,含义如下:
359+
* return the next cursor position, as below:
221360
* 0:遍历结束
361+
* scan finish
222362
* -1: 出错
363+
* some error happened
223364
* >0: 游标的下一个位置
365+
* the next cursor postion to scan
224366
*/
225367
int sscan(const char* key, int cursor, std::vector<string>& out,
226368
const char* pattern = NULL, const size_t* count = NULL);

0 commit comments

Comments
 (0)