Chinaunix首页 | 论坛 | 博客
  • 博客访问: 29335556
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: 系统运维

2009-10-18 11:19:20

存储命令
Storage commands
首先,客户端会发送一行像这样的命令: First, the client sends a command line which looks like this:
\r\n
- 是 set, add, 或者 repalce - is "set", "add" or "replace"
  • set 意思是 “储存此数据”
  • add 意思是 “储存此数据,只在服务器*未*保留此键值的数据时”
  • replace意思是 “储存此数据,只在服务器*曾*保留此键值的数据时”
  • "set" means "store this data".
  • "add" means "store this data, but only if the server *doesn't* already
    hold data for this key".
  • "replace" means "store this data, but only if the server *does*
    already hold data for this key".
- 是接下来的客户端所要求储存的数据的键值 - is the key under which the client asks to store the data
- 是在取回内容时,与数据和发送块一同保存服务器上的任意16位无符号整形(用十进制来书写)。客户端可以用它作为“位域”来存储一些特定的信息;它对服务器是不透明的。 - is an arbitrary 16-bit unsigned integer (written out in
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.
- 是终止时间。如果为0,该项永不过期(虽然它可能被删除,以便为其他缓存项目腾出位置)。如果非0(Unix时间戳或当前时刻的秒偏移),到达终止时间后,客户端无法再获得这项内容。 - is expiration time. If it's 0, the item never expires
(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).
- 是随后的数据区块的字节长度,不包括用于分野的“\r\n”。它可以是0(这时后面跟随一个空的数据区块)。 - is the number of bytes in the data block to follow, *not*
including the delimiting \r\n. may be zero (in which case
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 *\r\n
- * 表示一个或多个键值,由空格隔开的字串 - * means one or more key strings separated by whitespace.
这行命令以后,客户端的等待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
\r\n
- 是所发送的键名 - is the key for the item being sent
- 是存储命令所设置的记号

- is the flags value set by the storage command

- 是随后数据块的长度,*不包括* 它的界定符“\r\n” - is the length of the data block to follow, *not* including
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
- 是客户端希望服务器删除的内容的键名 - is the key of the item the client wishes the server to 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 \r\n

decr \r\n
- 是客户端希望修改的内容的建名

- is the key of the item the client wishes to change

- 是客户端要增加/减少的总数。 - is the amount by which the client wants to increase/decrease
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
- \r\n ,是 增加/减少 。 - \r\n , where is the new value of the item's data,
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
settings, documented below. In the other form it has some arguments:

stats \r\n
通过,服务器传回各种内部数据。因为随时可能发生变动,本文不提供参数的种类及其传回数据。 Depending on , various internal data is sent by the server. The
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.
阅读(1059) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~