存储命令 |
Storage commands |
首先,客户端会发送一行像这样的命令: | First, the client sends a command line which looks like this: |
- |
- |
|
|
- |
- |
- |
- decimal) that the server stores along with the data and sends back when the item is retrieved. Clients may use this as a bit field to store data-specific information; this field is opaque to the server. |
- |
- (although it may be deleted from the cache to make place for other items). If it's non-zero (either Unix time or offset in seconds from current time), it is guaranteed that clients will not be able to retrieve this item after the expiration time arrives (measured by server time). |
- |
- including the delimiting \r\n. it's followed by an empty data block). |
|
|
在这一行以后,客户端发送数据区块。 | After this line, the client sends the data block: |
\r\n | |
- 是大段的8位数据,其长度由前面的命令行中的 |
- is a chunk of arbitrary 8-bit data of length from the previous line. |
发送命令行和数据区块以后,客户端等待回复,可能的回复如下: | After sending the command line and the data blockm the client awaits the reply, which may be: |
- "STORED\r\n" | |
表明成功. | to indicate success. |
- "NOT_STORED\r\n" | |
表明数据没有被存储,但不是因为发生错误。这通常意味着add 或 replace命令的条件不成立,或者,项目已经位列删除队列(参考后文的“delete”命令)。 | to indicate the data was not stored, but not because of an error. This normally means that either that the condition for an "add" or a "replace" command wasn't met, or that the item is in a delete queue (see the "delete" command below). |
|
|
取回命令 |
Retrieval command |
一行取回命令如下: | The retrieval command looks like this: |
get |
|
- |
- |
这行命令以后,客户端的等待0个或多个项目,每项都会收到一行文本,然后跟着数据区块。所有项目传送完毕后,服务器发送以下字串: | After this command, the client expects zero or more items, each of which is received as a text line followed by a data block. After all the items have been transmitted, the server sends the string |
"END\r\n" | |
来指示回应完毕。 | to indicate the end of response. |
服务器用以下形式发送每项内容: | Each item sent by the server looks like this: |
VALUE \r\n |
|
- |
- |
- |
- |
- |
- its delimiting \r\n |
- 是发送的数据 | - is the data for this item. |
如果在取回请求中发送了一些键名,而服务器没有送回项目列表,这意味着服务器没这些键名(可能因为它们从未被存储,或者为给其他内容腾出空间而被删除,或者到期,或者被已客户端删除)。 | If some of the keys appearing in a retrieval request are not sent back by the server in the item list this means that the server does not hold items with such keys (because they were never stored, or stored but deleted to make space for more items, or expired, or explicitly deleted by a client). |
|
|
删除 |
Deletion |
命令“delete”允许从外部删除内容: | The command "delete" allows for explicit deletion of items: |
delete |
|
- |
- |
- | - |
The parameter | |
此命令有一行回应: | The response line to this command can be one of: |
- "DELETED\r\n" | |
表示执行成功 | to indicate success |
- "NOT_FOUND\r\n" | |
表示没有找到这项内容 | to indicate that the item with this key was not found. |
参考随后的“flush_all”命令使所有内容无效 | See the "flush_all" command below for immediate invalidation of all existing items. |
|
|
增加/减少 |
Increment/Decrement |
命 令 “incr” 和 “decr”被用来修改数据,当一些内容需要 替换、增加 或减少时。这些数据必须是十进制的32位无符号整新。如果不是,则当作0来处理。修改的内容必须存在,当使用“incr”/“decr”命令修改不存在的 内容时,不会被当作0处理,而是操作失败。 | Commands "incr" and "decr" are used to change data for some item in-place, incrementing or decrementing it. The data for the item is treated as decimal representation of a 32-bit unsigned integer. If the current data value does not conform to such a representation, the commands behave as if the value were 0. Also, the item must already exist for incr/decr to work; these commands won't pretend that a non-existent key exists with value 0; instead, they will fail. |
客户端发送命令行: | The client sends the command line: |
incr 或 decr |
|
- |
- |
- |
- the item. It is a decimal representation of a 32-bit unsigned integer. |
回复为以下集中情形: |
The response will be one of: |
- "NOT_FOUND\r\n" | |
指示该项内容的值,不存在。 | to indicate the item with this value was not found |
- |
- after the increment/decrement operation was carried out. |
注意"decr"命令发生下溢:如果客户端尝试减少的结果小于0时,结果会是0。"incr" 命令不会发生溢出。 | Note that underflow in the "decr" command is caught: if a client tries to decrease the value below 0, the new value will be 0. Overflow in the "incr" command is not checked. |
……
|
Note also that decrementing a number such that it loses length isn't guaranteed to decrement its returned length. The number MAY be space-padded at the end, but this is purely an implementation optimization, so you also shouldn't rely on that. |
|
|
状态 |
Statistics |
命令"stats" 被用于查询服务器的运行状态和其他内部数据。有两种格式。不带参数的: | The command "stats" is used to query the server about statistics it maintains and other internal data. It has two forms. Without arguments: |
stats\r\n | |
这会在随后输出各项状态、设定值和文档。另一种格式带有一些参数: |
it causes the server to output general-purpose statistics and
|
stats |
|
通过 |
Depending on kinds of arguments and the data sent are not documented in this vesion of the protocol, and are subject to change for the convenience of memcache developers. |