注: 本文档主要根据原作者的英文文档protocol.en.txt写成,做了一些翻译工作和添加了一些例子以及一些需要注意的地方。如果本文档对你有所帮助,欢迎关注我的新浪微博:http://weibo.com/u/1857063732 如果有建议,欢迎发送到我的邮箱xiaoxuye1988@163.com 目前就职于 欢聚时代(YY), 从事于后台开发工作
Updating/Deletingdata
英文原文如下
The'find_modify' request has the following syntax.
<indexid> <op> <vlen><v1> ... <vn> [LIM] [IN] [FILTER ...] MOD
MODis a sequence of the following parameters.
<mop> <m1> ... <mk>
-<mop> is 'U' (update), '+' (increment), '-' (decrement), 'D' (delete),
'U?', '+?', '-?', or 'D?'. If the '?' suffixis specified, it returns
the contents of the records beforemodification (as if it's a 'find'
request), instead of the number of modifiedrecords.
-<m1> ... <mk> specifies the column values to set. The length of<m1> ...
<mk> must be smaller than or equal tothe length of <columns> specified by
the corresponding 'open_index' request. If<mop> is 'D', these parameters
are ignored. If <mop> is '+' or '-',values must be numeric. If <mop> is
'-' and it attempts to change a column valuefrom negative to positive or
positive to negative, the column value is notmodified.
‘find_modify’请求有以下参数:
<indexid><op> <vlen> <v1> ... <vn> [LIM] [IN] [FILTER ...] MOD
MOD是一项参数的一个序列:
<mop> <m1> ... <mk>
-<mop>是'U' (update), '+' (increment), '-' (decrement), 'D' (delete),
'U?', '+?', '-?', or 'D?'。如果’?’这个后缀被指定,那么这个请求将会返回那些记录被修改前的内容(类似’find’请求),而不是返回修改行的行数。
-<m1> ... <mk>指定了这些列所要赋的值。<m1> ... <mk>的个数必须不大于个在其相对于的‘open_index’请求中指定的参数<columns>的的列数。如果<mop>是 'D',这些参数就会被忽略。如果<mop> 是 '+' 或 '-',这些值必须是数字。如果<mop>是'-'并且这个请求试图将一个列的值由负值变为正值或由正值变为负值的话,那么其实这个列的值没有发生变化。
Responsefor 'find_modify'
If'find_modify' is succeeded, HandlerSocket returns a line of the following
syntax.
0 1 <nummod>
-<nummod> is the number of modified rows.
-As an exception, if the '?' suffix is specified in <mop>, a response has
the syntax of a response for 'find' instead.
'find_modify'请求的回应:
如果'find_modify'请求成功发送,HandlerSocket 会返回以下一行:
0 1 <nummod>
- <nummod>是被修改的行的行数。
-一个特例,如果'?'这个后缀在<mop>中被指定,回应将被‘find’的请求的回应形式所替代。
主要所使用的成员函数的原型:
virtual void request_buf_exec_generic(size_t pst_id, conststring_ref& op,
const string_ref *kvs,size_t kvslen, uint32_t limit, uint32_t skip,
const string_ref&mod_op, const string_ref *mvs, size_t mvslen,
const hstcpcli_filter*fils = 0, size_t filslen = 0,
int invalues_keypart = -1,const string_ref *invalues = 0,
size_t invalueslen =0) = 0;
1.update用法
const string kTestUpdateOp("U");
const string_refkTestUpdateOpRef(kTestUpdateOp.data(), kTestUpdateOp.size());
cli->request_buf_exec_generic(indexid,kTestEqualOpRef,&vec[0],vec_length,limit,offset,kTestUpdateOpRef,&vec_in[0],vec_in_length);
‘U?’用法类似。返回结果不同之处请看前文翻译。
2.’+’用法
const string kTestUpdateOp("+");
const string_refkTestUpdateOpRef(kTestUpdateOp.data(), kTestUpdateOp.size());
cli->request_buf_exec_generic(indexid,kTestEqualOpRef,&vec[0],vec_length,limit,offset,kTestUpdateOpRef,&vec_in[0],vec_in_length);
注意:当使用这个用法是,不能加一个负数,会导致意外结果,在我的测试中,对于int型,将修改成为int型的最大值。
’+?’用法类似。返回结果不同之处请看前文翻译。
3‘-’用法
const string kTestUpdateOp("-");
const string_refkTestUpdateOpRef(kTestUpdateOp.data(), kTestUpdateOp.size());
cli->request_buf_exec_generic(indexid,kTestEqualOpRef,&vec[0],vec_length,limit,offset,kTestUpdateOpRef,&vec_in[0],vec_in_length);
注意情况情况前文翻译。
’-?’用法类似。返回结果不同之处请看前文翻译。
4.delete用法
const string kTestUpdateOp("D");
const string_refkTestUpdateOpRef(kTestUpdateOp.data(), kTestUpdateOp.size());
cli->request_buf_exec_generic(indexid,kTestEqualOpRef,&vec[0],vec_length,limit,offset,kTestUpdateOpRef,0,0);
’D?’用法类似。返回结果不同之处请看前文翻译。
5.[FILTER ...]参照Getting data中的用法。