Blame doc/protocol.txt

Packit 4e8bc4
Protocol
Packit 4e8bc4
--------
Packit 4e8bc4
Packit 4e8bc4
Clients of memcached communicate with server through TCP connections.
Packit 4e8bc4
(A UDP interface is also available; details are below under "UDP
Packit 4e8bc4
protocol.") A given running memcached server listens on some
Packit 4e8bc4
(configurable) port; clients connect to that port, send commands to
Packit 4e8bc4
the server, read responses, and eventually close the connection.
Packit 4e8bc4
Packit 4e8bc4
There is no need to send any command to end the session. A client may
Packit 4e8bc4
just close the connection at any moment it no longer needs it. Note,
Packit 4e8bc4
however, that clients are encouraged to cache their connections rather
Packit 4e8bc4
than reopen them every time they need to store or retrieve data.  This
Packit 4e8bc4
is because memcached is especially designed to work very efficiently
Packit 4e8bc4
with a very large number (many hundreds, more than a thousand if
Packit 4e8bc4
necessary) of open connections. Caching connections will eliminate the
Packit 4e8bc4
overhead associated with establishing a TCP connection (the overhead
Packit 4e8bc4
of preparing for a new connection on the server side is insignificant
Packit 4e8bc4
compared to this).
Packit 4e8bc4
Packit 4e8bc4
There are two kinds of data sent in the memcache protocol: text lines
Packit 4e8bc4
and unstructured data.  Text lines are used for commands from clients
Packit 4e8bc4
and responses from servers. Unstructured data is sent when a client
Packit 4e8bc4
wants to store or retrieve data. The server will transmit back
Packit 4e8bc4
unstructured data in exactly the same way it received it, as a byte
Packit 4e8bc4
stream. The server doesn't care about byte order issues in
Packit 4e8bc4
unstructured data and isn't aware of them. There are no limitations on
Packit 4e8bc4
characters that may appear in unstructured data; however, the reader
Packit 4e8bc4
of such data (either a client or a server) will always know, from a
Packit 4e8bc4
preceding text line, the exact length of the data block being
Packit 4e8bc4
transmitted.
Packit 4e8bc4
Packit 4e8bc4
Text lines are always terminated by \r\n. Unstructured data is _also_
Packit 4e8bc4
terminated by \r\n, even though \r, \n or any other 8-bit characters
Packit 4e8bc4
may also appear inside the data. Therefore, when a client retrieves
Packit 4e8bc4
data from a server, it must use the length of the data block (which it
Packit 4e8bc4
will be provided with) to determine where the data block ends, and not
Packit 4e8bc4
the fact that \r\n follows the end of the data block, even though it
Packit 4e8bc4
does.
Packit 4e8bc4
Packit 4e8bc4
Keys
Packit 4e8bc4
----
Packit 4e8bc4
Packit 4e8bc4
Data stored by memcached is identified with the help of a key. A key
Packit 4e8bc4
is a text string which should uniquely identify the data for clients
Packit 4e8bc4
that are interested in storing and retrieving it.  Currently the
Packit 4e8bc4
length limit of a key is set at 250 characters (of course, normally
Packit 4e8bc4
clients wouldn't need to use such long keys); the key must not include
Packit 4e8bc4
control characters or whitespace.
Packit 4e8bc4
Packit 4e8bc4
Commands
Packit 4e8bc4
--------
Packit 4e8bc4
Packit 4e8bc4
There are three types of commands.
Packit 4e8bc4
Packit 4e8bc4
Storage commands (there are six: "set", "add", "replace", "append"
Packit 4e8bc4
"prepend" and "cas") ask the server to store some data identified by a
Packit 4e8bc4
key. The client sends a command line, and then a data block; after
Packit 4e8bc4
that the client expects one line of response, which will indicate
Packit 4e8bc4
success or failure.
Packit 4e8bc4
Packit 4e8bc4
Retrieval commands ("get", "gets", "gat", and "gats") ask the server to
Packit 4e8bc4
retrieve data corresponding to a set of keys (one or more keys in one
Packit 4e8bc4
request). The client sends a command line, which includes all the
Packit 4e8bc4
requested keys; after that for each item the server finds it sends to
Packit 4e8bc4
the client one response line with information about the item, and one
Packit 4e8bc4
data block with the item's data; this continues until the server
Packit 4e8bc4
finished with the "END" response line.
Packit 4e8bc4
Packit 4e8bc4
All other commands don't involve unstructured data. In all of them,
Packit 4e8bc4
the client sends one command line, and expects (depending on the
Packit 4e8bc4
command) either one line of response, or several lines of response
Packit 4e8bc4
ending with "END" on the last line.
Packit 4e8bc4
Packit 4e8bc4
A command line always starts with the name of the command, followed by
Packit 4e8bc4
parameters (if any) delimited by whitespace. Command names are
Packit 4e8bc4
lower-case and are case-sensitive.
Packit 4e8bc4
Packit 4e8bc4
Meta Commands [EXPERIMENTAL: MAY CHANGE]
Packit 4e8bc4
-------------
Packit 4e8bc4
Packit 4e8bc4
Meta commands are a set of new ASCII-based commands. They follow the same
Packit 4e8bc4
structure of the basic commands but have a new flexible feature set.
Packit 4e8bc4
Meta commands incorporate most features available in the binary protocol, as
Packit 4e8bc4
well as a flag system to make the commands flexible rather than having a
Packit 4e8bc4
large number of high level commands. These commands completely replace the
Packit 4e8bc4
usage of basic Storage and Retrieval commands.
Packit 4e8bc4
Packit 4e8bc4
Meta commands are EXPERIMENTAL and may change syntax as of this writing. They
Packit 4e8bc4
are documented below the basic commands.
Packit 4e8bc4
Packit 4e8bc4
These work mixed with normal protocol commands on the same connection. All
Packit 4e8bc4
existing commands continue to work. The meta commands will not replace
Packit 4e8bc4
specialized commands that do not sit in the Storage or Retrieval categories
Packit 4e8bc4
noted in the 'Commands' section above.
Packit 4e8bc4
Packit 4e8bc4
All meta commands follow a basic syntax:
Packit 4e8bc4
Packit 4e8bc4
cm <key> <flags> <token1> <token2> <...>\r\n
Packit 4e8bc4
Packit 4e8bc4
Where 'cm' is a 2 character command code. The number of tokens supplied is
Packit 4e8bc4
based off of the flags used.
Packit 4e8bc4
Packit 4e8bc4
Responses look like:
Packit 4e8bc4
Packit 4e8bc4
RC <flags> <token1> <token2> <...>\r\n
Packit 4e8bc4
Packit 4e8bc4
Where 'rc' is a 2 character return code. The number of tokens returned are
Packit 4e8bc4
based off of the flags used.
Packit 4e8bc4
Packit 4e8bc4
Flags are single character codes, ie 'q' or 'k' or 'I', which adjust the
Packit 4e8bc4
behavior of the command. The flags are reflected in the response. The order of
Packit 4e8bc4
which tokens are consumed or returned depend on the order of the flags given.
Packit 4e8bc4
For example, a metaget with flags of 'st' would return tokens for "size" and
Packit 4e8bc4
"TTL remaining" in that order. 'ts' would return "TTL remaining" then "size".
Packit 4e8bc4
Packit 4e8bc4
Syntax errors are handled the same as noted under 'Error strings' section
Packit 4e8bc4
below.
Packit 4e8bc4
Packit 4e8bc4
For usage examples beyond basic syntax, please see the wiki:
Packit 4e8bc4
https://github.com/memcached/memcached/wiki/MetaCommands
Packit 4e8bc4
Packit 4e8bc4
Expiration times
Packit 4e8bc4
----------------
Packit 4e8bc4
Packit 4e8bc4
Some commands involve a client sending some kind of expiration time
Packit 4e8bc4
(relative to an item or to an operation requested by the client) to
Packit 4e8bc4
the server. In all such cases, the actual value sent may either be
Packit 4e8bc4
Unix time (number of seconds since January 1, 1970, as a 32-bit
Packit 4e8bc4
value), or a number of seconds starting from current time. In the
Packit 4e8bc4
latter case, this number of seconds may not exceed 60*60*24*30 (number
Packit 4e8bc4
of seconds in 30 days); if the number sent by a client is larger than
Packit 4e8bc4
that, the server will consider it to be real Unix time value rather
Packit 4e8bc4
than an offset from current time.
Packit 4e8bc4
Packit 4e8bc4
Note that a TTL of 1 will sometimes immediately expire. Time is internally
Packit 4e8bc4
updated on second boundaries, which makes expiration time roughly +/- 1s.
Packit 4e8bc4
This more proportionally affects very low TTL's.
Packit 4e8bc4
Packit 4e8bc4
Error strings
Packit 4e8bc4
-------------
Packit 4e8bc4
Packit 4e8bc4
Each command sent by a client may be answered with an error string
Packit 4e8bc4
from the server. These error strings come in three types:
Packit 4e8bc4
Packit 4e8bc4
- "ERROR\r\n"
Packit 4e8bc4
Packit 4e8bc4
  means the client sent a nonexistent command name.
Packit 4e8bc4
Packit 4e8bc4
- "CLIENT_ERROR <error>\r\n"
Packit 4e8bc4
Packit 4e8bc4
  means some sort of client error in the input line, i.e. the input
Packit 4e8bc4
  doesn't conform to the protocol in some way. <error> is a
Packit 4e8bc4
  human-readable error string.
Packit 4e8bc4
Packit 4e8bc4
- "SERVER_ERROR <error>\r\n"
Packit 4e8bc4
Packit 4e8bc4
  means some sort of server error prevents the server from carrying
Packit 4e8bc4
  out the command. <error> is a human-readable error string. In cases
Packit 4e8bc4
  of severe server errors, which make it impossible to continue
Packit 4e8bc4
  serving the client (this shouldn't normally happen), the server will
Packit 4e8bc4
  close the connection after sending the error line. This is the only
Packit 4e8bc4
  case in which the server closes a connection to a client.
Packit 4e8bc4
Packit 4e8bc4
Packit 4e8bc4
In the descriptions of individual commands below, these error lines
Packit 4e8bc4
are not again specifically mentioned, but clients must allow for their
Packit 4e8bc4
possibility.
Packit 4e8bc4
Packit 4e8bc4
Authentication
Packit 4e8bc4
--------------
Packit 4e8bc4
Packit 4e8bc4
Optional username/password token authentication (see -Y option). Used by
Packit 4e8bc4
sending a fake "set" command with any key:
Packit 4e8bc4
Packit 4e8bc4
set <key> <flags> <exptime> <bytes>\r\n
Packit 4e8bc4
username password\r\n
Packit 4e8bc4
Packit 4e8bc4
key, flags, and exptime are ignored for authentication. Bytes is the length
Packit 4e8bc4
of the username/password payload.
Packit 4e8bc4
Packit 4e8bc4
- "STORED\r\n" indicates success. After this point any command should work
Packit 4e8bc4
  normally.
Packit 4e8bc4
Packit 4e8bc4
- "CLIENT_ERROR [message]\r\n" will be returned if authentication fails for
Packit 4e8bc4
  any reason.
Packit 4e8bc4
Packit 4e8bc4
Storage commands
Packit 4e8bc4
----------------
Packit 4e8bc4
Packit 4e8bc4
First, the client sends a command line which looks like this:
Packit 4e8bc4
Packit 4e8bc4
<command name> <key> <flags> <exptime> <bytes> [noreply]\r\n
Packit 4e8bc4
cas <key> <flags> <exptime> <bytes> <cas unique> [noreply]\r\n
Packit 4e8bc4
Packit 4e8bc4
- <command name> is "set", "add", "replace", "append" or "prepend"
Packit 4e8bc4
Packit 4e8bc4
  "set" means "store this data".
Packit 4e8bc4
Packit 4e8bc4
  "add" means "store this data, but only if the server *doesn't* already
Packit 4e8bc4
  hold data for this key".
Packit 4e8bc4
Packit 4e8bc4
  "replace" means "store this data, but only if the server *does*
Packit 4e8bc4
  already hold data for this key".
Packit 4e8bc4
Packit 4e8bc4
  "append" means "add this data to an existing key after existing data".
Packit 4e8bc4
Packit 4e8bc4
  "prepend" means "add this data to an existing key before existing data".
Packit 4e8bc4
Packit 4e8bc4
  The append and prepend commands do not accept flags or exptime.
Packit 4e8bc4
  They update existing data portions, and ignore new flag and exptime
Packit 4e8bc4
  settings.
Packit 4e8bc4
Packit 4e8bc4
  "cas" is a check and set operation which means "store this data but
Packit 4e8bc4
  only if no one else has updated since I last fetched it."
Packit 4e8bc4
Packit 4e8bc4
- <key> is the key under which the client asks to store the data
Packit 4e8bc4
Packit 4e8bc4
- <flags> is an arbitrary 16-bit unsigned integer (written out in
Packit 4e8bc4
  decimal) that the server stores along with the data and sends back
Packit 4e8bc4
  when the item is retrieved. Clients may use this as a bit field to
Packit 4e8bc4
  store data-specific information; this field is opaque to the server.
Packit 4e8bc4
  Note that in memcached 1.2.1 and higher, flags may be 32-bits, instead
Packit 4e8bc4
  of 16, but you might want to restrict yourself to 16 bits for
Packit 4e8bc4
  compatibility with older versions.
Packit 4e8bc4
Packit 4e8bc4
- <exptime> is expiration time. If it's 0, the item never expires
Packit 4e8bc4
  (although it may be deleted from the cache to make place for other
Packit 4e8bc4
  items). If it's non-zero (either Unix time or offset in seconds from
Packit 4e8bc4
  current time), it is guaranteed that clients will not be able to
Packit 4e8bc4
  retrieve this item after the expiration time arrives (measured by
Packit 4e8bc4
  server time). If a negative value is given the item is immediately
Packit 4e8bc4
  expired.
Packit 4e8bc4
Packit 4e8bc4
- <bytes> is the number of bytes in the data block to follow, *not*
Packit 4e8bc4
  including the delimiting \r\n. <bytes> may be zero (in which case
Packit 4e8bc4
  it's followed by an empty data block).
Packit 4e8bc4
Packit 4e8bc4
- <cas unique> is a unique 64-bit value of an existing entry.
Packit 4e8bc4
  Clients should use the value returned from the "gets" command
Packit 4e8bc4
  when issuing "cas" updates.
Packit 4e8bc4
Packit 4e8bc4
- "noreply" optional parameter instructs the server to not send the
Packit 4e8bc4
  reply.  NOTE: if the request line is malformed, the server can't
Packit 4e8bc4
  parse "noreply" option reliably.  In this case it may send the error
Packit 4e8bc4
  to the client, and not reading it on the client side will break
Packit 4e8bc4
  things.  Client should construct only valid requests.
Packit 4e8bc4
Packit 4e8bc4
After this line, the client sends the data block:
Packit 4e8bc4
Packit 4e8bc4
<data block>\r\n
Packit 4e8bc4
Packit 4e8bc4
- <data block> is a chunk of arbitrary 8-bit data of length <bytes>
Packit 4e8bc4
  from the previous line.
Packit 4e8bc4
Packit 4e8bc4
After sending the command line and the data block the client awaits
Packit 4e8bc4
the reply, which may be:
Packit 4e8bc4
Packit 4e8bc4
- "STORED\r\n", to indicate success.
Packit 4e8bc4
Packit 4e8bc4
- "NOT_STORED\r\n" to indicate the data was not stored, but not
Packit 4e8bc4
because of an error. This normally means that the
Packit 4e8bc4
condition for an "add" or a "replace" command wasn't met.
Packit 4e8bc4
Packit 4e8bc4
- "EXISTS\r\n" to indicate that the item you are trying to store with
Packit 4e8bc4
a "cas" command has been modified since you last fetched it.
Packit 4e8bc4
Packit 4e8bc4
- "NOT_FOUND\r\n" to indicate that the item you are trying to store
Packit 4e8bc4
with a "cas" command did not exist.
Packit 4e8bc4
Packit 4e8bc4
Packit 4e8bc4
Retrieval command:
Packit 4e8bc4
------------------
Packit 4e8bc4
Packit 4e8bc4
The retrieval commands "get" and "gets" operate like this:
Packit 4e8bc4
Packit 4e8bc4
get <key>*\r\n
Packit 4e8bc4
gets <key>*\r\n
Packit 4e8bc4
Packit 4e8bc4
- <key>* means one or more key strings separated by whitespace.
Packit 4e8bc4
Packit 4e8bc4
After this command, the client expects zero or more items, each of
Packit 4e8bc4
which is received as a text line followed by a data block. After all
Packit 4e8bc4
the items have been transmitted, the server sends the string
Packit 4e8bc4
Packit 4e8bc4
"END\r\n"
Packit 4e8bc4
Packit 4e8bc4
to indicate the end of response.
Packit 4e8bc4
Packit 4e8bc4
Each item sent by the server looks like this:
Packit 4e8bc4
Packit 4e8bc4
VALUE <key> <flags> <bytes> [<cas unique>]\r\n
Packit 4e8bc4
<data block>\r\n
Packit 4e8bc4
Packit 4e8bc4
- <key> is the key for the item being sent
Packit 4e8bc4
Packit 4e8bc4
- <flags> is the flags value set by the storage command
Packit 4e8bc4
Packit 4e8bc4
- <bytes> is the length of the data block to follow, *not* including
Packit 4e8bc4
  its delimiting \r\n
Packit 4e8bc4
Packit 4e8bc4
- <cas unique> is a unique 64-bit integer that uniquely identifies
Packit 4e8bc4
  this specific item.
Packit 4e8bc4
Packit 4e8bc4
- <data block> is the data for this item.
Packit 4e8bc4
Packit 4e8bc4
If some of the keys appearing in a retrieval request are not sent back
Packit 4e8bc4
by the server in the item list this means that the server does not
Packit 4e8bc4
hold items with such keys (because they were never stored, or stored
Packit 4e8bc4
but deleted to make space for more items, or expired, or explicitly
Packit 4e8bc4
deleted by a client).
Packit 4e8bc4
Packit 4e8bc4
Packit 4e8bc4
Deletion
Packit 4e8bc4
--------
Packit 4e8bc4
Packit 4e8bc4
The command "delete" allows for explicit deletion of items:
Packit 4e8bc4
Packit 4e8bc4
delete <key> [noreply]\r\n
Packit 4e8bc4
Packit 4e8bc4
- <key> is the key of the item the client wishes the server to delete
Packit 4e8bc4
Packit 4e8bc4
- "noreply" optional parameter instructs the server to not send the
Packit 4e8bc4
  reply.  See the note in Storage commands regarding malformed
Packit 4e8bc4
  requests.
Packit 4e8bc4
Packit 4e8bc4
The response line to this command can be one of:
Packit 4e8bc4
Packit 4e8bc4
- "DELETED\r\n" to indicate success
Packit 4e8bc4
Packit 4e8bc4
- "NOT_FOUND\r\n" to indicate that the item with this key was not
Packit 4e8bc4
  found.
Packit 4e8bc4
Packit 4e8bc4
See the "flush_all" command below for immediate invalidation
Packit 4e8bc4
of all existing items.
Packit 4e8bc4
Packit 4e8bc4
Packit 4e8bc4
Increment/Decrement
Packit 4e8bc4
-------------------
Packit 4e8bc4
Packit 4e8bc4
Commands "incr" and "decr" are used to change data for some item
Packit 4e8bc4
in-place, incrementing or decrementing it. The data for the item is
Packit 4e8bc4
treated as decimal representation of a 64-bit unsigned integer.  If
Packit 4e8bc4
the current data value does not conform to such a representation, the
Packit 4e8bc4
incr/decr commands return an error (memcached <= 1.2.6 treated the
Packit 4e8bc4
bogus value as if it were 0, leading to confusion). Also, the item
Packit 4e8bc4
must already exist for incr/decr to work; these commands won't pretend
Packit 4e8bc4
that a non-existent key exists with value 0; instead, they will fail.
Packit 4e8bc4
Packit 4e8bc4
The client sends the command line:
Packit 4e8bc4
Packit 4e8bc4
incr <key> <value> [noreply]\r\n
Packit 4e8bc4
Packit 4e8bc4
or
Packit 4e8bc4
Packit 4e8bc4
decr <key> <value> [noreply]\r\n
Packit 4e8bc4
Packit 4e8bc4
- <key> is the key of the item the client wishes to change
Packit 4e8bc4
Packit 4e8bc4
- <value> is the amount by which the client wants to increase/decrease
Packit 4e8bc4
the item. It is a decimal representation of a 64-bit unsigned integer.
Packit 4e8bc4
Packit 4e8bc4
- "noreply" optional parameter instructs the server to not send the
Packit 4e8bc4
  reply.  See the note in Storage commands regarding malformed
Packit 4e8bc4
  requests.
Packit 4e8bc4
Packit 4e8bc4
The response will be one of:
Packit 4e8bc4
Packit 4e8bc4
- "NOT_FOUND\r\n" to indicate the item with this value was not found
Packit 4e8bc4
Packit 4e8bc4
- <value>\r\n , where <value> is the new value of the item's data,
Packit 4e8bc4
  after the increment/decrement operation was carried out.
Packit 4e8bc4
Packit 4e8bc4
Note that underflow in the "decr" command is caught: if a client tries
Packit 4e8bc4
to decrease the value below 0, the new value will be 0.  Overflow in
Packit 4e8bc4
the "incr" command will wrap around the 64 bit mark.
Packit 4e8bc4
Packit 4e8bc4
Note also that decrementing a number such that it loses length isn't
Packit 4e8bc4
guaranteed to decrement its returned length.  The number MAY be
Packit 4e8bc4
space-padded at the end, but this is purely an implementation
Packit 4e8bc4
optimization, so you also shouldn't rely on that.
Packit 4e8bc4
Packit 4e8bc4
Touch
Packit 4e8bc4
-----
Packit 4e8bc4
Packit 4e8bc4
The "touch" command is used to update the expiration time of an existing item
Packit 4e8bc4
without fetching it.
Packit 4e8bc4
Packit 4e8bc4
touch <key> <exptime> [noreply]\r\n
Packit 4e8bc4
Packit 4e8bc4
- <key> is the key of the item the client wishes the server to touch
Packit 4e8bc4
Packit 4e8bc4
- <exptime> is expiration time. Works the same as with the update commands
Packit 4e8bc4
  (set/add/etc). This replaces the existing expiration time. If an existing
Packit 4e8bc4
  item were to expire in 10 seconds, but then was touched with an
Packit 4e8bc4
  expiration time of "20", the item would then expire in 20 seconds.
Packit 4e8bc4
Packit 4e8bc4
- "noreply" optional parameter instructs the server to not send the
Packit 4e8bc4
  reply.  See the note in Storage commands regarding malformed
Packit 4e8bc4
  requests.
Packit 4e8bc4
Packit 4e8bc4
The response line to this command can be one of:
Packit 4e8bc4
Packit 4e8bc4
- "TOUCHED\r\n" to indicate success
Packit 4e8bc4
Packit 4e8bc4
- "NOT_FOUND\r\n" to indicate that the item with this key was not
Packit 4e8bc4
  found.
Packit 4e8bc4
Packit 4e8bc4
Get And Touch
Packit 4e8bc4
-------------
Packit 4e8bc4
Packit 4e8bc4
The "gat" and "gats" commands are used to fetch items and update the
Packit 4e8bc4
expiration time of an existing items.
Packit 4e8bc4
Packit 4e8bc4
gat <exptime> <key>*\r\n
Packit 4e8bc4
gats <exptime> <key>*\r\n
Packit 4e8bc4
Packit 4e8bc4
- <exptime> is expiration time.
Packit 4e8bc4
Packit 4e8bc4
- <key>* means one or more key strings separated by whitespace.
Packit 4e8bc4
Packit 4e8bc4
After this command, the client expects zero or more items, each of
Packit 4e8bc4
which is received as a text line followed by a data block. After all
Packit 4e8bc4
the items have been transmitted, the server sends the string
Packit 4e8bc4
Packit 4e8bc4
"END\r\n"
Packit 4e8bc4
Packit 4e8bc4
to indicate the end of response.
Packit 4e8bc4
Packit 4e8bc4
Each item sent by the server looks like this:
Packit 4e8bc4
Packit 4e8bc4
VALUE <key> <flags> <bytes> [<cas unique>]\r\n
Packit 4e8bc4
<data block>\r\n
Packit 4e8bc4
Packit 4e8bc4
- <key> is the key for the item being sent
Packit 4e8bc4
Packit 4e8bc4
- <flags> is the flags value set by the storage command
Packit 4e8bc4
Packit 4e8bc4
- <bytes> is the length of the data block to follow, *not* including
Packit 4e8bc4
  its delimiting \r\n
Packit 4e8bc4
Packit 4e8bc4
- <cas unique> is a unique 64-bit integer that uniquely identifies
Packit 4e8bc4
  this specific item.
Packit 4e8bc4
Packit 4e8bc4
- <data block> is the data for this item.
Packit 4e8bc4
Packit 4e8bc4
Meta Debug
Packit 4e8bc4
----------
Packit 4e8bc4
Packit 4e8bc4
The meta debug command is a human readable dump of all available internal
Packit 4e8bc4
metadata of an item, minus the value.
Packit 4e8bc4
Packit 4e8bc4
me <key>\r\n
Packit 4e8bc4
Packit 4e8bc4
- <key> means one key string.
Packit 4e8bc4
Packit 4e8bc4
The response looks like:
Packit 4e8bc4
Packit 4e8bc4
ME <key> <k>=<v>*\r\nEN\r\n
Packit 4e8bc4
Packit 4e8bc4
Each of the keys and values are the internal data for the item.
Packit 4e8bc4
Packit 4e8bc4
exp   = expiration time
Packit 4e8bc4
la    = time in seconds since last access
Packit 4e8bc4
cas   = CAS ID
Packit 4e8bc4
fetch = whether an item has been fetched before
Packit 4e8bc4
cls   = slab class id
Packit 4e8bc4
size  = total size in bytes
Packit 4e8bc4
Packit 4e8bc4
Others may be added.
Packit 4e8bc4
Packit 4e8bc4
Meta Get
Packit 4e8bc4
--------
Packit 4e8bc4
Packit 4e8bc4
The meta get command is the generic command for retrieving key data from
Packit 4e8bc4
memcached. Based on the flags supplied, it can replace all of the commands:
Packit 4e8bc4
"get", "gets", "gat", "gats", "touch", as well as adding new options.
Packit 4e8bc4
Packit 4e8bc4
mg <key> <flags> <tokens>*\r\n
Packit 4e8bc4
Packit 4e8bc4
- <key> means one key string. Unlike "get" metaget can only take a single key.
Packit 4e8bc4
Packit 4e8bc4
- <flags> are a set of single character codes ended with a space or newline.
Packit 4e8bc4
Packit 4e8bc4
- <tokens>* means zero or more tokens, based on the flags supplied. They are
Packit 4e8bc4
  consumed in order specified by the flags.
Packit 4e8bc4
Packit 4e8bc4
After this command, the client expects an item to be returned, received as a
Packit 4e8bc4
text line followed by an optional data block. After the item is transferred,
Packit 4e8bc4
the server sends the string
Packit 4e8bc4
Packit 4e8bc4
"EN\r\n"
Packit 4e8bc4
Packit 4e8bc4
to indicate the end of the response.
Packit 4e8bc4
Packit 4e8bc4
If a response line appearing in a retrieval request is not sent back
Packit 4e8bc4
by the server this means that the server does not
Packit 4e8bc4
have the item (because it was never stored, or stored
Packit 4e8bc4
but deleted to make space for more items, or expired, or explicitly
Packit 4e8bc4
deleted by a client).
Packit 4e8bc4
Packit 4e8bc4
An item sent by the server looks like:
Packit 4e8bc4
Packit 4e8bc4
VA <flags> <tokens>*\r\n
Packit 4e8bc4
<data block>\r\n
Packit 4e8bc4
Packit 4e8bc4
- <flags> are a reflection of the flags sent to the server. Extra flags can be
Packit 4e8bc4
  added to the response based on the execution of the command.
Packit 4e8bc4
Packit 4e8bc4
- <tokens>* are tokens returned by the server, based on the flags supplied.
Packit 4e8bc4
  They are added in order specified by the flags sent.
Packit 4e8bc4
Packit 4e8bc4
- <data block> is the data for this item. Note that the data black is
Packit 4e8bc4
  optional, requiring the 'v' flag to be supplied.
Packit 4e8bc4
Packit 4e8bc4
The flags used by the 'mg' command are:
Packit 4e8bc4
Packit 4e8bc4
- c: return item cas token
Packit 4e8bc4
- f: return client flags token
Packit 4e8bc4
- h: return whether item has been hit before as a 0 or 1
Packit 4e8bc4
- k: return key as a token
Packit 4e8bc4
- l: return time since item was last accessed in seconds
Packit 4e8bc4
- O (token): opaque value, consumes a token and copies back with response
Packit 4e8bc4
- q: use noreply semantics for return codes.
Packit 4e8bc4
- s: return item size token
Packit 4e8bc4
- t: return item TTL remaining in seconds (-1 for unlimited)
Packit 4e8bc4
- u: don't bump the item in the LRU
Packit 4e8bc4
- v: return item value in <data block>
Packit 4e8bc4
Packit 4e8bc4
These flags can modify the item:
Packit 4e8bc4
- N (token): vivify on miss, takes TTL as a argument
Packit 4e8bc4
- R (token): if token is less than remaining TTL win for recache
Packit 4e8bc4
- T (token): update remaining TTL
Packit 4e8bc4
Packit 4e8bc4
These extra flags can be added to the response:
Packit 4e8bc4
- W: client has "won" the recache flag
Packit 4e8bc4
- X: item is stale
Packit 4e8bc4
- Z: tem has already sent a winning flag
Packit 4e8bc4
Packit 4e8bc4
The flags are now repeated with detailed information where useful:
Packit 4e8bc4
Packit 4e8bc4
- h: return whether item has been hit before as a 0 or 1
Packit 4e8bc4
- l: return time since item was last accessed in seconds
Packit 4e8bc4
Packit 4e8bc4
The above two flags return the value of "hit before?" and "last access time"
Packit 4e8bc4
before the command was processed. Otherwise this would always show a 1 for
Packit 4e8bc4
hit or always show an access time of "0" unless combined with the "u" flag.
Packit 4e8bc4
Packit 4e8bc4
- O (token): opaque value, consumes a token and copies back with response
Packit 4e8bc4
Packit 4e8bc4
The O (opaque) token is used by this and other commands to allow easier
Packit 4e8bc4
pipelining of requests while saving bytes on the wire for responses. For
Packit 4e8bc4
example: if pipelining three get commands together, you may not know which
Packit 4e8bc4
response belongs to which without also retrieving the key. If the key is very
Packit 4e8bc4
long this can generate a lot of traffic, especially if the data block is very
Packit 4e8bc4
small. Instead, you can supply an "O" flag for each mg with tokens of "1" "2"
Packit 4e8bc4
and "3", to match up responses to the request.
Packit 4e8bc4
Packit 4e8bc4
Opaque tokens may be up to 32 bytes in length, and are a string similar to
Packit 4e8bc4
keys.
Packit 4e8bc4
Packit 4e8bc4
- q: use noreply semantics for return codes.
Packit 4e8bc4
Packit 4e8bc4
Noreply is a method of reducing the amount of data sent back by memcached to
Packit 4e8bc4
the client for normal responses. In the case of metaget, if an item is not
Packit 4e8bc4
available the "VA" line is normally not sent, and the response is terminated by
Packit 4e8bc4
"EN\r\n".
Packit 4e8bc4
Packit 4e8bc4
With noreply enabled, the "EN\r\n" marker is suppressed. This allows you to
Packit 4e8bc4
pipeline several mg's together and read all of the responses without the
Packit 4e8bc4
"EN\r\n" lines in the middle.
Packit 4e8bc4
Packit 4e8bc4
Errors are always returned.
Packit 4e8bc4
Packit 4e8bc4
- u: don't bump the item in the LRU
Packit 4e8bc4
Packit 4e8bc4
It is possible to access an item without causing it to be "bumped" to the head
Packit 4e8bc4
of the LRU. This also avoids marking an item as being hit or updating its last
Packit 4e8bc4
access time.
Packit 4e8bc4
Packit 4e8bc4
- v: return item value in <data block>
Packit 4e8bc4
Packit 4e8bc4
The data block for a metaget response is optional, requiring this flag to be
Packit 4e8bc4
passed in.
Packit 4e8bc4
Packit 4e8bc4
These flags can modify the item:
Packit 4e8bc4
- N (token): vivify on miss, takes TTL as a argument
Packit 4e8bc4
Packit 4e8bc4
Used to help with so called "dog piling" problems with recaching of popular
Packit 4e8bc4
items. If supplied, and metaget does not find the item in cache, it will
Packit 4e8bc4
create a stub item with the key and TTL as supplied. If such an item is
Packit 4e8bc4
created a 'W' flag is added to the response to indicate to a client that they
Packit 4e8bc4
have "won" the right to recache an item.
Packit 4e8bc4
Packit 4e8bc4
The automatically created item has 0 bytes of data.
Packit 4e8bc4
Packit 4e8bc4
Further requests will see a 'Z' flag to indicate that another client has
Packit 4e8bc4
already received the win flag.
Packit 4e8bc4
Packit 4e8bc4
Can be combined with CAS flags to gate the update further.
Packit 4e8bc4
Packit 4e8bc4
- R (token): if token is less than remaining TTL win for recache
Packit 4e8bc4
Packit 4e8bc4
Similar to and can be combined with 'N'. If the remaining TTL of an item is
Packit 4e8bc4
below the supplied token, return a 'W' flag to indicate the client has "won"
Packit 4e8bc4
the right to recache an item. This allows refreshing an item before it leads to
Packit 4e8bc4
a miss.
Packit 4e8bc4
Packit 4e8bc4
- T (token): update remaining TTL
Packit 4e8bc4
Packit 4e8bc4
Similar to "touch" and "gat" commands, updates the remaining TTL of an item if
Packit 4e8bc4
hit.
Packit 4e8bc4
Packit 4e8bc4
These extra flags can be added to the response:
Packit 4e8bc4
- W: client has "won" the recache flag
Packit 4e8bc4
Packit 4e8bc4
When combined with N or R flags, a client may be informed they have "won"
Packit 4e8bc4
ownership of a cache item. This allows a single client to be atomically
Packit 4e8bc4
notified that it should cache or update an item. Further clients requesting
Packit 4e8bc4
the item can use the existing data block (if valid or stale), retry, wait, or
Packit 4e8bc4
take some other action while the item is missing.
Packit 4e8bc4
Packit 4e8bc4
This is used when the act of recaching an item can cause undue load on another
Packit 4e8bc4
system (CPU, database accesses, time, and so on).
Packit 4e8bc4
Packit 4e8bc4
- X: item is stale
Packit 4e8bc4
Packit 4e8bc4
Items can be marked as stale by the metadelete command. This indicates to the
Packit 4e8bc4
client that an object needs to be updated, and that it should make a decision
Packit 4e8bc4
o if potentially stale data is safe to use.
Packit 4e8bc4
Packit 4e8bc4
This is used when you want to convince clients to recache an item, but it's
Packit 4e8bc4
safe to use pre-existing data while the recache happens.
Packit 4e8bc4
Packit 4e8bc4
- Z: item has already sent a winning flag
Packit 4e8bc4
Packit 4e8bc4
When combined with the X flag, or the client N or R flags, this extra response
Packit 4e8bc4
flag indicates to a client that a different client is responsible for
Packit 4e8bc4
recaching this item. If there is data supplied it may use it, or the client
Packit 4e8bc4
may decide to retry later or take some other action.
Packit 4e8bc4
Packit 4e8bc4
Meta Set
Packit 4e8bc4
--------
Packit 4e8bc4
Packit 4e8bc4
The meta set command a generic command for storing data to memcached. Based on
Packit 4e8bc4
the flags supplied, it can replace the commands: "set", "cas". as well as
Packit 4e8bc4
adding new options.
Packit 4e8bc4
Packit 4e8bc4
ms <key> <flags> <tokens>*\r\n
Packit 4e8bc4
Packit 4e8bc4
- <key> means one key string.
Packit 4e8bc4
Packit 4e8bc4
- <flags> are a set of single character codes ended with a space or newline.
Packit 4e8bc4
Packit 4e8bc4
- <tokens>* means zero or more tokens, based on the flags supplied. They are
Packit 4e8bc4
  consumed in order specified by the flags.
Packit 4e8bc4
Packit 4e8bc4
After this line, the client sends the data block:
Packit 4e8bc4
Packit 4e8bc4
<data block>\r\n
Packit 4e8bc4
Packit 4e8bc4
- <data block> is a chunk of arbitrary 8-bit data of length supplied by an 'S'
Packit 4e8bc4
  flag and token from the previous line. If no 'S' flag is supplied the data
Packit 4e8bc4
  is assumed to be 0 length.
Packit 4e8bc4
Packit 4e8bc4
After sending the command line and the data block the client awaits
Packit 4e8bc4
the reply, which is of the format:
Packit 4e8bc4
Packit 4e8bc4
CD <flags> <tokens>*\r\n
Packit 4e8bc4
Packit 4e8bc4
Where CD is one of:
Packit 4e8bc4
Packit 4e8bc4
- "ST" (STORED), to indicate success.
Packit 4e8bc4
Packit 4e8bc4
- "NS" (NOT_STORED), to indicate the data was not stored, but not
Packit 4e8bc4
because of an error.
Packit 4e8bc4
Packit 4e8bc4
- "EX" (EXISTS), to indicate that the item you are trying to store with
Packit 4e8bc4
CAS semantics has been modified since you last fetched it.
Packit 4e8bc4
Packit 4e8bc4
- "NF" (NOT_FOUND), to indicate that the item you are trying to store
Packit 4e8bc4
with CAS semantics did not exist.
Packit 4e8bc4
Packit 4e8bc4
The flags used by the 'ms' command are:
Packit 4e8bc4
Packit 4e8bc4
- C (token): compare CAS value when storing item
Packit 4e8bc4
- F (token): set client flags to token (32 bit unsigned numeric)
Packit 4e8bc4
- I: invalid. set-to-invalid if CAS is older than it should be.
Packit 4e8bc4
- k: return key as a token
Packit 4e8bc4
- O (token): opaque value, consumes a token and copies back with response
Packit 4e8bc4
- q: use noreply semantics for return codes
Packit 4e8bc4
- S (token): size of <data block> to store
Packit 4e8bc4
- T (token): Time-To-Live for item, see "Expiration" above.
Packit 4e8bc4
Packit 4e8bc4
The flags are now repeated with detailed information where useful:
Packit 4e8bc4
Packit 4e8bc4
- C (token): compare CAS value when storing item
Packit 4e8bc4
Packit 4e8bc4
Similar to the basic "cas" command, only store item if the supplied token
Packit 4e8bc4
matches the current CAS value of the item. When combined with the 'I' flag, a
Packit 4e8bc4
CAS value that is _lower_ than the current value may be accepted, but the item
Packit 4e8bc4
will be marked as "stale", returning the X flag with mget requests.
Packit 4e8bc4
Packit 4e8bc4
- F (token): set client flags to token (32 bit unsigned numeric)
Packit 4e8bc4
Packit 4e8bc4
Sets flags to 0 if not supplied.
Packit 4e8bc4
Packit 4e8bc4
- I: invalid. set-to-invalid if CAS is older than it should be.
Packit 4e8bc4
Packit 4e8bc4
Functional when combined with 'C' flag above.
Packit 4e8bc4
Packit 4e8bc4
- O (token): opaque value, consumes a token and copies back with response
Packit 4e8bc4
Packit 4e8bc4
See description under 'Meta Get'
Packit 4e8bc4
Packit 4e8bc4
- q: use noreply semantics for return codes
Packit 4e8bc4
Packit 4e8bc4
Noreply is a method of reducing the amount of data sent back by memcached to
Packit 4e8bc4
the client for normal responses. In the case of metaset, a response that would
Packit 4e8bc4
start with "ST" (STORED) will not be sent. Any other code, such as "EX"
Packit 4e8bc4
(EXISTS) will still be returned.
Packit 4e8bc4
Packit 4e8bc4
Errors are always returned.
Packit 4e8bc4
Packit 4e8bc4
Meta Delete
Packit 4e8bc4
-----------
Packit 4e8bc4
Packit 4e8bc4
The meta delete command allows for explicit deletion of items, as well as
Packit 4e8bc4
marking items as "stale" to allow serving items as stale during revalidation.
Packit 4e8bc4
Packit 4e8bc4
md <key> <flags> <tokens>*\r\n
Packit 4e8bc4
Packit 4e8bc4
- <key> means one key string.
Packit 4e8bc4
Packit 4e8bc4
- <flags> are a set of single character codes ended with a space or newline.
Packit 4e8bc4
Packit 4e8bc4
- <tokens>* means zero or more tokens, based on the flags supplied. They are
Packit 4e8bc4
  consumed in order specified by the flags.
Packit 4e8bc4
Packit 4e8bc4
The response is in the format:
Packit 4e8bc4
Packit 4e8bc4
CD <flags> <tokens>*\r\n
Packit 4e8bc4
Packit 4e8bc4
Where CD is one of:
Packit 4e8bc4
Packit 4e8bc4
- "DE" (DELETED), to indicate success
Packit 4e8bc4
Packit 4e8bc4
- "NF" (NOT_FOUND), to indicate that the item with this key was not found.
Packit 4e8bc4
Packit 4e8bc4
- "EX" (EXISTS), to indicate that the supplied CAS token does not match the
Packit 4e8bc4
  stored item.
Packit 4e8bc4
Packit 4e8bc4
The flags used by the 'md' command are:
Packit 4e8bc4
Packit 4e8bc4
- C (token): compare CAS value
Packit 4e8bc4
- I: invalidate. mark as stale, bumps CAS.
Packit 4e8bc4
- k: return key
Packit 4e8bc4
- O: opaque to copy back.
Packit 4e8bc4
- q: noreply
Packit 4e8bc4
- T (token): updates TTL, only when paired with the 'I' flag
Packit 4e8bc4
Packit 4e8bc4
The flags are now repeated with detailed information where useful:
Packit 4e8bc4
Packit 4e8bc4
- C (token): compare CAS value
Packit 4e8bc4
Packit 4e8bc4
Can be used to only delete or mark-stale if a supplied CAS value matches.
Packit 4e8bc4
Packit 4e8bc4
- I: invalidate. mark as stale, bumps CAS.
Packit 4e8bc4
Packit 4e8bc4
Instead of removing an item, this will give the item a new CAS value and mark
Packit 4e8bc4
it as stale. This means when it is later fetched by metaget, the client will
Packit 4e8bc4
be supplied an 'X' flag to show the data is stale and needs to be recached.
Packit 4e8bc4
Packit 4e8bc4
- O (token): opaque to copy back.
Packit 4e8bc4
Packit 4e8bc4
See description under 'Meta Get'
Packit 4e8bc4
Packit 4e8bc4
- q: noreply
Packit 4e8bc4
Packit 4e8bc4
See description under 'Meta Set'. In the case of meta delete, this will hide
Packit 4e8bc4
response lines with the code "DE". It will still return any other responses.
Packit 4e8bc4
Packit 4e8bc4
- T (token): updates TTL, only when paired with the 'I' flag
Packit 4e8bc4
Packit 4e8bc4
When marking an item as stale with 'I', the 'T' flag can be used to update the
Packit 4e8bc4
TTL as well; limiting the amount of time an item will live while stale and
Packit 4e8bc4
waiting to be recached.
Packit 4e8bc4
Packit 4e8bc4
Meta No-Op
Packit 4e8bc4
----------
Packit 4e8bc4
Packit 4e8bc4
The meta no-op command exists solely to return a static response code. It
Packit 4e8bc4
takes no flags, no arguments.
Packit 4e8bc4
Packit 4e8bc4
This returns the static response:
Packit 4e8bc4
Packit 4e8bc4
"EN\r\n"
Packit 4e8bc4
Packit 4e8bc4
Similar to a meta get command.
Packit 4e8bc4
Packit 4e8bc4
This command is useful when used with the 'q' flag and pipelining commands.
Packit 4e8bc4
For example, with 'mg' the response lines are blank on miss, and the 'q' flag
Packit 4e8bc4
will hide the "EN\r\n" response code. If pipelining several 'mg's together
Packit 4e8bc4
with noreply semantics, an "mn\r\n" command can be tagged to the end of the
Packit 4e8bc4
chain, which will return an "EN\r\n", signalling to a client that all previous
Packit 4e8bc4
commands have been processed.
Packit 4e8bc4
Packit 4e8bc4
Slabs Reassign
Packit 4e8bc4
--------------
Packit 4e8bc4
Packit 4e8bc4
NOTE: This command is subject to change as of this writing.
Packit 4e8bc4
Packit 4e8bc4
The slabs reassign command is used to redistribute memory once a running
Packit 4e8bc4
instance has hit its limit. It might be desirable to have memory laid out
Packit 4e8bc4
differently than was automatically assigned after the server started.
Packit 4e8bc4
Packit 4e8bc4
slabs reassign <source class> <dest class>\r\n
Packit 4e8bc4
Packit 4e8bc4
- <source class> is an id number for the slab class to steal a page from
Packit 4e8bc4
Packit 4e8bc4
A source class id of -1 means "pick from any valid class"
Packit 4e8bc4
Packit 4e8bc4
- <dest class> is an id number for the slab class to move a page to
Packit 4e8bc4
Packit 4e8bc4
The response line could be one of:
Packit 4e8bc4
Packit 4e8bc4
- "OK" to indicate the page has been scheduled to move
Packit 4e8bc4
Packit 4e8bc4
- "BUSY [message]" to indicate a page is already being processed, try again
Packit 4e8bc4
  later.
Packit 4e8bc4
Packit 4e8bc4
- "BADCLASS [message]" a bad class id was specified
Packit 4e8bc4
Packit 4e8bc4
- "NOSPARE [message]" source class has no spare pages
Packit 4e8bc4
Packit 4e8bc4
- "NOTFULL [message]" dest class must be full to move new pages to it
Packit 4e8bc4
Packit 4e8bc4
- "UNSAFE [message]" source class cannot move a page right now
Packit 4e8bc4
Packit 4e8bc4
- "SAME [message]" must specify different source/dest ids.
Packit 4e8bc4
Packit 4e8bc4
Slabs Automove
Packit 4e8bc4
--------------
Packit 4e8bc4
Packit 4e8bc4
NOTE: This command is subject to change as of this writing.
Packit 4e8bc4
Packit 4e8bc4
The slabs automove command enables a background thread which decides on its
Packit 4e8bc4
own when to move memory between slab classes. Its implementation and options
Packit 4e8bc4
will likely be in flux for several versions. See the wiki/mailing list for
Packit 4e8bc4
more details.
Packit 4e8bc4
Packit 4e8bc4
The automover can be enabled or disabled at runtime with this command.
Packit 4e8bc4
Packit 4e8bc4
slabs automove <0|1>
Packit 4e8bc4
Packit 4e8bc4
- 0|1|2 is the indicator on whether to enable the slabs automover or not.
Packit 4e8bc4
Packit 4e8bc4
The response should always be "OK\r\n"
Packit 4e8bc4
Packit 4e8bc4
- <0> means to set the thread on standby
Packit 4e8bc4
Packit 4e8bc4
- <1> means to return pages to a global pool when there are more than 2 pages
Packit 4e8bc4
  worth of free chunks in a slab class. Pages are then re-assigned back into
Packit 4e8bc4
  other classes as-needed.
Packit 4e8bc4
Packit 4e8bc4
- <2> is a highly aggressive mode which causes pages to be moved every time
Packit 4e8bc4
  there is an eviction. It is not recommended to run for very long in this
Packit 4e8bc4
  mode unless your access patterns are very well understood.
Packit 4e8bc4
Packit 4e8bc4
LRU Tuning
Packit 4e8bc4
----------
Packit 4e8bc4
Packit 4e8bc4
Memcached supports multiple LRU algorithms, with a few tunables. Effort is
Packit 4e8bc4
made to have sane defaults however you are able to tune while the daemon is
Packit 4e8bc4
running.
Packit 4e8bc4
Packit 4e8bc4
The traditional model is "flat" mode, which is a single LRU chain per slab
Packit 4e8bc4
class. The newer (with `-o modern` or `-o lru_maintainer`) is segmented into
Packit 4e8bc4
HOT, WARM, COLD. There is also a TEMP LRU. See doc/new_lru.txt for details.
Packit 4e8bc4
Packit 4e8bc4
lru <tune|mode|temp_ttl> <option list>
Packit 4e8bc4
Packit 4e8bc4
- "tune" takes numeric arguments "percent hot", "percent warm",
Packit 4e8bc4
  "max hot factor", "max warm age factor". IE: "lru tune 10 25 0.1 2.0".
Packit 4e8bc4
  This would cap HOT_LRU at 10% of the cache, or tail is idle longer than
Packit 4e8bc4
  10% of COLD_LRU. WARM_LRU is up to 25% of cache, or tail is idle longer
Packit 4e8bc4
  than 2x COLD_LRU.
Packit 4e8bc4
Packit 4e8bc4
- "mode" <flat|segmented>: "flat" is traditional mode. "segmented" uses
Packit 4e8bc4
  HOT|WARM|COLD split. "segmented" mode requires `-o lru_maintainer` at start
Packit 4e8bc4
  time. If switching from segmented to flat mode, the background thread will
Packit 4e8bc4
  pull items from HOT|WARM into COLD queue.
Packit 4e8bc4
Packit 4e8bc4
- "temp_ttl" <ttl>: If TTL is less than zero, disable usage of TEMP_LRU. If
Packit 4e8bc4
  zero or above, items set with a TTL lower than this will go into TEMP_LRU
Packit 4e8bc4
  and be unevictable until they naturally expire or are otherwise deleted or
Packit 4e8bc4
  replaced.
Packit 4e8bc4
Packit 4e8bc4
The response line could be one of:
Packit 4e8bc4
Packit 4e8bc4
- "OK" to indicate a successful update of the settings.
Packit 4e8bc4
Packit 4e8bc4
- "ERROR [message]" to indicate a failure or improper arguments.
Packit 4e8bc4
Packit 4e8bc4
LRU_Crawler
Packit 4e8bc4
-----------
Packit 4e8bc4
Packit 4e8bc4
NOTE: This command (and related commands) are subject to change as of this
Packit 4e8bc4
writing.
Packit 4e8bc4
Packit 4e8bc4
The LRU Crawler is an optional background thread which will walk from the tail
Packit 4e8bc4
toward the head of requested slab classes, actively freeing memory for expired
Packit 4e8bc4
items. This is useful if you have a mix of items with both long and short
Packit 4e8bc4
TTL's, but aren't accessed very often. This system is not required for normal
Packit 4e8bc4
usage, and can add small amounts of latency and increase CPU usage.
Packit 4e8bc4
Packit 4e8bc4
lru_crawler <enable|disable>
Packit 4e8bc4
Packit 4e8bc4
- Enable or disable the LRU Crawler background thread.
Packit 4e8bc4
Packit 4e8bc4
The response line could be one of:
Packit 4e8bc4
Packit 4e8bc4
- "OK" to indicate the crawler has been started or stopped.
Packit 4e8bc4
Packit 4e8bc4
- "ERROR [message]" something went wrong while enabling or disabling.
Packit 4e8bc4
Packit 4e8bc4
lru_crawler sleep <microseconds>
Packit 4e8bc4
Packit 4e8bc4
- The number of microseconds to sleep in between each item checked for
Packit 4e8bc4
  expiration. Smaller numbers will obviously impact the system more.
Packit 4e8bc4
  A value of "0" disables the sleep, "1000000" (one second) is the max.
Packit 4e8bc4
Packit 4e8bc4
The response line could be one of:
Packit 4e8bc4
Packit 4e8bc4
- "OK"
Packit 4e8bc4
Packit 4e8bc4
- "CLIENT_ERROR [message]" indicating a format or bounds issue.
Packit 4e8bc4
Packit 4e8bc4
lru_crawler tocrawl <32u>
Packit 4e8bc4
Packit 4e8bc4
- The maximum number of items to inspect in a slab class per run request. This
Packit 4e8bc4
  allows you to avoid scanning all of very large slabs when it is unlikely to
Packit 4e8bc4
  find items to expire.
Packit 4e8bc4
Packit 4e8bc4
The response line could be one of:
Packit 4e8bc4
Packit 4e8bc4
- "OK"
Packit 4e8bc4
Packit 4e8bc4
- "CLIENT_ERROR [message]" indicating a format or bound issue.
Packit 4e8bc4
Packit 4e8bc4
lru_crawler crawl <classid,classid,classid|all>
Packit 4e8bc4
Packit 4e8bc4
- Takes a single, or a list of, numeric classids (ie: 1,3,10). This instructs
Packit 4e8bc4
  the crawler to start at the tail of each of these classids and run to the
Packit 4e8bc4
  head. The crawler cannot be stopped or restarted until it completes the
Packit 4e8bc4
  previous request.
Packit 4e8bc4
Packit 4e8bc4
  The special keyword "all" instructs it to crawl all slabs with items in
Packit 4e8bc4
  them.
Packit 4e8bc4
Packit 4e8bc4
The response line could be one of:
Packit 4e8bc4
Packit 4e8bc4
- "OK" to indicate successful launch.
Packit 4e8bc4
Packit 4e8bc4
- "BUSY [message]" to indicate the crawler is already processing a request.
Packit 4e8bc4
Packit 4e8bc4
- "BADCLASS [message]" to indicate an invalid class was specified.
Packit 4e8bc4
Packit 4e8bc4
lru_crawler metadump <classid,classid,classid|all>
Packit 4e8bc4
Packit 4e8bc4
- Similar in function to the above "lru_crawler crawl" command, this function
Packit 4e8bc4
  outputs one line for every valid item found in the matching slab classes.
Packit 4e8bc4
  Similar to "cachedump", but does not lock the cache and can return all
Packit 4e8bc4
  items, not just 1MB worth.
Packit 4e8bc4
Packit 4e8bc4
  Lines are in "key=value key2=value2" format, with value being URI encoded
Packit 4e8bc4
  (ie: %20 for a space).
Packit 4e8bc4
Packit 4e8bc4
  The exact keys available are subject to change, but will include at least:
Packit 4e8bc4
Packit 4e8bc4
  "key", "exp" (expiration time), "la", (last access time), "cas",
Packit 4e8bc4
  "fetch" (if item has been fetched before).
Packit 4e8bc4
Packit 4e8bc4
The response line could be one of:
Packit 4e8bc4
Packit 4e8bc4
- "OK" to indicate successful launch.
Packit 4e8bc4
Packit 4e8bc4
- "BUSY [message]" to indicate the crawler is already processing a request.
Packit 4e8bc4
Packit 4e8bc4
- "BADCLASS [message]" to indicate an invalid class was specified.
Packit 4e8bc4
Packit 4e8bc4
Watchers
Packit 4e8bc4
--------
Packit 4e8bc4
Packit 4e8bc4
Watchers are a way to connect to memcached and inspect what's going on
Packit 4e8bc4
internally. This is an evolving feature so new endpoints should show up over
Packit 4e8bc4
time.
Packit 4e8bc4
Packit 4e8bc4
watch <fetchers|mutations|evictions>
Packit 4e8bc4
Packit 4e8bc4
- Turn connection into a watcher. Options can be stacked and are
Packit 4e8bc4
  space-separated. Logs will be sent to the watcher until it disconnects.
Packit 4e8bc4
Packit 4e8bc4
The response line could be one of:
Packit 4e8bc4
Packit 4e8bc4
- "OK" to indicate the watcher is ready to send logs.
Packit 4e8bc4
Packit 4e8bc4
- "ERROR [message]" something went wrong while enabling.
Packit 4e8bc4
Packit 4e8bc4
The response format is in "key=value key2=value2" format, for easy parsing.
Packit 4e8bc4
Lines are prepending with "ts=" for a timestamp and "gid=" for a global ID
Packit 4e8bc4
number of the log line. Given how logs are collected internally they may be
Packit 4e8bc4
printed out of order. If this is important the GID may be used to put log
Packit 4e8bc4
lines back in order.
Packit 4e8bc4
Packit 4e8bc4
The value of keys (and potentially other things) are "URI encoded". Since most
Packit 4e8bc4
keys used conform to standard ASCII, this should have no effect. For keys with
Packit 4e8bc4
less standard or binary characters, "%NN"'s are inserted to represent the
Packit 4e8bc4
byte, ie: "n%2Cfoo" for "n,foo".
Packit 4e8bc4
Packit 4e8bc4
The arguments are:
Packit 4e8bc4
Packit 4e8bc4
- "fetchers": Currently emits logs every time an item is fetched internally.
Packit 4e8bc4
  This means a "set" command would also emit an item_get log, as it checks for
Packit 4e8bc4
  an item before replacing it. Multigets should also emit multiple lines.
Packit 4e8bc4
Packit 4e8bc4
- "mutations": Currently emits logs when an item is stored in most cases.
Packit 4e8bc4
  Shows errors for most cases when items cannot be stored.
Packit 4e8bc4
Packit 4e8bc4
- "evictions": Shows some information about items as they are evicted from the
Packit 4e8bc4
  cache. Useful in seeing if items being evicted were actually used, and which
Packit 4e8bc4
  keys are getting removed.
Packit 4e8bc4
Packit 4e8bc4
Statistics
Packit 4e8bc4
----------
Packit 4e8bc4
Packit 4e8bc4
The command "stats" is used to query the server about statistics it
Packit 4e8bc4
maintains and other internal data. It has two forms. Without
Packit 4e8bc4
arguments:
Packit 4e8bc4
Packit 4e8bc4
stats\r\n
Packit 4e8bc4
Packit 4e8bc4
it causes the server to output general-purpose statistics and
Packit 4e8bc4
settings, documented below.  In the other form it has some arguments:
Packit 4e8bc4
Packit 4e8bc4
stats <args>\r\n
Packit 4e8bc4
Packit 4e8bc4
Depending on <args>, various internal data is sent by the server. The
Packit 4e8bc4
kinds of arguments and the data sent are not documented in this version
Packit 4e8bc4
of the protocol, and are subject to change for the convenience of
Packit 4e8bc4
memcache developers.
Packit 4e8bc4
Packit 4e8bc4
Packit 4e8bc4
General-purpose statistics
Packit 4e8bc4
--------------------------
Packit 4e8bc4
Packit 4e8bc4
Upon receiving the "stats" command without arguments, the server sends
Packit 4e8bc4
a number of lines which look like this:
Packit 4e8bc4
Packit 4e8bc4
STAT <name> <value>\r\n
Packit 4e8bc4
Packit 4e8bc4
The server terminates this list with the line
Packit 4e8bc4
Packit 4e8bc4
END\r\n
Packit 4e8bc4
Packit 4e8bc4
In each line of statistics, <name> is the name of this statistic, and
Packit 4e8bc4
<value> is the data.  The following is the list of all names sent in
Packit 4e8bc4
response to the "stats" command, together with the type of the value
Packit 4e8bc4
sent for this name, and the meaning of the value.
Packit 4e8bc4
Packit 4e8bc4
In the type column below, "32u" means a 32-bit unsigned integer, "64u"
Packit 4e8bc4
means a 64-bit unsigned integer. '32u.32u' means two 32-bit unsigned
Packit 4e8bc4
integers separated by a colon (treat this as a floating point number).
Packit 4e8bc4
Packit 4e8bc4
|-----------------------+---------+-------------------------------------------|
Packit 4e8bc4
| Name                  | Type    | Meaning                                   |
Packit 4e8bc4
|-----------------------+---------+-------------------------------------------|
Packit 4e8bc4
| pid                   | 32u     | Process id of this server process         |
Packit 4e8bc4
| uptime                | 32u     | Number of secs since the server started   |
Packit 4e8bc4
| time                  | 32u     | current UNIX time according to the server |
Packit 4e8bc4
| version               | string  | Version string of this server             |
Packit 4e8bc4
| pointer_size          | 32      | Default size of pointers on the host OS   |
Packit 4e8bc4
|                       |         | (generally 32 or 64)                      |
Packit 4e8bc4
| rusage_user           | 32u.32u | Accumulated user time for this process    |
Packit 4e8bc4
|                       |         | (seconds:microseconds)                    |
Packit 4e8bc4
| rusage_system         | 32u.32u | Accumulated system time for this process  |
Packit 4e8bc4
|                       |         | (seconds:microseconds)                    |
Packit 4e8bc4
| curr_items            | 64u     | Current number of items stored            |
Packit 4e8bc4
| total_items           | 64u     | Total number of items stored since        |
Packit 4e8bc4
|                       |         | the server started                        |
Packit 4e8bc4
| bytes                 | 64u     | Current number of bytes used              |
Packit 4e8bc4
|                       |         | to store items                            |
Packit 4e8bc4
| max_connections       | 32u     | Max number of simultaneous connections    |
Packit 4e8bc4
| curr_connections      | 32u     | Number of open connections                |
Packit 4e8bc4
| total_connections     | 32u     | Total number of connections opened since  |
Packit 4e8bc4
|                       |         | the server started running                |
Packit 4e8bc4
| rejected_connections  | 64u     | Conns rejected in maxconns_fast mode      |
Packit 4e8bc4
| connection_structures | 32u     | Number of connection structures allocated |
Packit 4e8bc4
|                       |         | by the server                             |
Packit 4e8bc4
| reserved_fds          | 32u     | Number of misc fds used internally        |
Packit 4e8bc4
| cmd_get               | 64u     | Cumulative number of retrieval reqs       |
Packit 4e8bc4
| cmd_set               | 64u     | Cumulative number of storage reqs         |
Packit 4e8bc4
| cmd_flush             | 64u     | Cumulative number of flush reqs           |
Packit 4e8bc4
| cmd_touch             | 64u     | Cumulative number of touch reqs           |
Packit 4e8bc4
| get_hits              | 64u     | Number of keys that have been requested   |
Packit 4e8bc4
|                       |         | and found present                         |
Packit 4e8bc4
| get_misses            | 64u     | Number of items that have been requested  |
Packit 4e8bc4
|                       |         | and not found                             |
Packit 4e8bc4
| get_expired           | 64u     | Number of items that have been requested  |
Packit 4e8bc4
|                       |         | but had already expired.                  |
Packit 4e8bc4
| get_flushed           | 64u     | Number of items that have been requested  |
Packit 4e8bc4
|                       |         | but have been flushed via flush_all       |
Packit 4e8bc4
| delete_misses         | 64u     | Number of deletions reqs for missing keys |
Packit 4e8bc4
| delete_hits           | 64u     | Number of deletion reqs resulting in      |
Packit 4e8bc4
|                       |         | an item being removed.                    |
Packit 4e8bc4
| incr_misses           | 64u     | Number of incr reqs against missing keys. |
Packit 4e8bc4
| incr_hits             | 64u     | Number of successful incr reqs.           |
Packit 4e8bc4
| decr_misses           | 64u     | Number of decr reqs against missing keys. |
Packit 4e8bc4
| decr_hits             | 64u     | Number of successful decr reqs.           |
Packit 4e8bc4
| cas_misses            | 64u     | Number of CAS reqs against missing keys.  |
Packit 4e8bc4
| cas_hits              | 64u     | Number of successful CAS reqs.            |
Packit 4e8bc4
| cas_badval            | 64u     | Number of CAS reqs for which a key was    |
Packit 4e8bc4
|                       |         | found, but the CAS value did not match.   |
Packit 4e8bc4
| touch_hits            | 64u     | Number of keys that have been touched     |
Packit 4e8bc4
|                       |         | with a new expiration time                |
Packit 4e8bc4
| touch_misses          | 64u     | Number of items that have been touched    |
Packit 4e8bc4
|                       |         | and not found                             |
Packit 4e8bc4
| auth_cmds             | 64u     | Number of authentication commands         |
Packit 4e8bc4
|                       |         | handled, success or failure.              |
Packit 4e8bc4
| auth_errors           | 64u     | Number of failed authentications.         |
Packit 4e8bc4
| idle_kicks            | 64u     | Number of connections closed due to       |
Packit 4e8bc4
|                       |         | reaching their idle timeout.              |
Packit 4e8bc4
| evictions             | 64u     | Number of valid items removed from cache  |
Packit 4e8bc4
|                       |         | to free memory for new items              |
Packit 4e8bc4
| reclaimed             | 64u     | Number of times an entry was stored using |
Packit 4e8bc4
|                       |         | memory from an expired entry              |
Packit 4e8bc4
| bytes_read            | 64u     | Total number of bytes read by this server |
Packit 4e8bc4
|                       |         | from network                              |
Packit 4e8bc4
| bytes_written         | 64u     | Total number of bytes sent by this server |
Packit 4e8bc4
|                       |         | to network                                |
Packit 4e8bc4
| limit_maxbytes        | size_t  | Number of bytes this server is allowed to |
Packit 4e8bc4
|                       |         | use for storage.                          |
Packit 4e8bc4
| accepting_conns       | bool    | Whether or not server is accepting conns  |
Packit 4e8bc4
| listen_disabled_num   | 64u     | Number of times server has stopped        |
Packit 4e8bc4
|                       |         | accepting new connections (maxconns).     |
Packit 4e8bc4
| time_in_listen_disabled_us                                                  |
Packit 4e8bc4
|                       | 64u     | Number of microseconds in maxconns.       |
Packit 4e8bc4
| threads               | 32u     | Number of worker threads requested.       |
Packit 4e8bc4
|                       |         | (see doc/threads.txt)                     |
Packit 4e8bc4
| conn_yields           | 64u     | Number of times any connection yielded to |
Packit 4e8bc4
|                       |         | another due to hitting the -R limit.      |
Packit 4e8bc4
| hash_power_level      | 32u     | Current size multiplier for hash table    |
Packit 4e8bc4
| hash_bytes            | 64u     | Bytes currently used by hash tables       |
Packit 4e8bc4
| hash_is_expanding     | bool    | Indicates if the hash table is being      |
Packit 4e8bc4
|                       |         | grown to a new size                       |
Packit 4e8bc4
| expired_unfetched     | 64u     | Items pulled from LRU that were never     |
Packit 4e8bc4
|                       |         | touched by get/incr/append/etc before     |
Packit 4e8bc4
|                       |         | expiring                                  |
Packit 4e8bc4
| evicted_unfetched     | 64u     | Items evicted from LRU that were never    |
Packit 4e8bc4
|                       |         | touched by get/incr/append/etc.           |
Packit 4e8bc4
| evicted_active        | 64u     | Items evicted from LRU that had been hit  |
Packit 4e8bc4
|                       |         | recently but did not jump to top of LRU   |
Packit 4e8bc4
| slab_reassign_running | bool    | If a slab page is being moved             |
Packit 4e8bc4
| slabs_moved           | 64u     | Total slab pages moved                    |
Packit 4e8bc4
| crawler_reclaimed     | 64u     | Total items freed by LRU Crawler          |
Packit 4e8bc4
| crawler_items_checked | 64u     | Total items examined by LRU Crawler       |
Packit 4e8bc4
| lrutail_reflocked     | 64u     | Times LRU tail was found with active ref. |
Packit 4e8bc4
|                       |         | Items can be evicted to avoid OOM errors. |
Packit 4e8bc4
| moves_to_cold         | 64u     | Items moved from HOT/WARM to COLD LRU's   |
Packit 4e8bc4
| moves_to_warm         | 64u     | Items moved from COLD to WARM LRU         |
Packit 4e8bc4
| moves_within_lru      | 64u     | Items reshuffled within HOT or WARM LRU's |
Packit 4e8bc4
| direct_reclaims       | 64u     | Times worker threads had to directly      |
Packit 4e8bc4
|                       |         | reclaim or evict items.                   |
Packit 4e8bc4
| lru_crawler_starts    | 64u     | Times an LRU crawler was started          |
Packit 4e8bc4
| lru_maintainer_juggles                                                      |
Packit 4e8bc4
|                       | 64u     | Number of times the LRU bg thread woke up |
Packit 4e8bc4
| slab_global_page_pool | 32u     | Slab pages returned to global pool for    |
Packit 4e8bc4
|                       |         | reassignment to other slab classes.       |
Packit 4e8bc4
| slab_reassign_rescues | 64u     | Items rescued from eviction in page move  |
Packit 4e8bc4
| slab_reassign_evictions_nomem                                               |
Packit 4e8bc4
|                       | 64u     | Valid items evicted during a page move    |
Packit 4e8bc4
|                       |         | (due to no free memory in slab)           |
Packit 4e8bc4
| slab_reassign_chunk_rescues                                                 |
Packit 4e8bc4
|                       | 64u     | Individual sections of an item rescued    |
Packit 4e8bc4
|                       |         | during a page move.                       |
Packit 4e8bc4
| slab_reassign_inline_reclaim                                                |
Packit 4e8bc4
|                       | 64u     | Internal stat counter for when the page   |
Packit 4e8bc4
|                       |         | mover clears memory from the chunk        |
Packit 4e8bc4
|                       |         | freelist when it wasn't expecting to.     |
Packit 4e8bc4
| slab_reassign_busy_items                                                    |
Packit 4e8bc4
|                       | 64u     | Items busy during page move, requiring a  |
Packit 4e8bc4
|                       |         | retry before page can be moved.           |
Packit 4e8bc4
| slab_reassign_busy_deletes                                                  |
Packit 4e8bc4
|                       | 64u     | Items busy during page move, requiring    |
Packit 4e8bc4
|                       |         | deletion before page can be moved.        |
Packit 4e8bc4
| log_worker_dropped    | 64u     | Logs a worker never wrote due to full buf |
Packit 4e8bc4
| log_worker_written    | 64u     | Logs written by a worker, to be picked up |
Packit 4e8bc4
| log_watcher_skipped   | 64u     | Logs not sent to slow watchers.           |
Packit 4e8bc4
| log_watcher_sent      | 64u     | Logs written to watchers.                 |
Packit 4e8bc4
|-----------------------+---------+-------------------------------------------|
Packit 4e8bc4
Packit 4e8bc4
Settings statistics
Packit 4e8bc4
-------------------
Packit 4e8bc4
CAVEAT: This section describes statistics which are subject to change in the
Packit 4e8bc4
future.
Packit 4e8bc4
Packit 4e8bc4
The "stats" command with the argument of "settings" returns details of
Packit 4e8bc4
the settings of the running memcached.  This is primarily made up of
Packit 4e8bc4
the results of processing commandline options.
Packit 4e8bc4
Packit 4e8bc4
Note that these are not guaranteed to return in any specific order and
Packit 4e8bc4
this list may not be exhaustive.  Otherwise, this returns like any
Packit 4e8bc4
other stats command.
Packit 4e8bc4
Packit 4e8bc4
|-------------------+----------+----------------------------------------------|
Packit 4e8bc4
| Name              | Type     | Meaning                                      |
Packit 4e8bc4
|-------------------+----------+----------------------------------------------|
Packit 4e8bc4
| maxbytes          | size_t   | Maximum number of bytes allowed in the cache |
Packit 4e8bc4
| maxconns          | 32       | Maximum number of clients allowed.           |
Packit 4e8bc4
| tcpport           | 32       | TCP listen port.                             |
Packit 4e8bc4
| udpport           | 32       | UDP listen port.                             |
Packit 4e8bc4
| inter             | string   | Listen interface.                            |
Packit 4e8bc4
| verbosity         | 32       | 0 = none, 1 = some, 2 = lots                 |
Packit 4e8bc4
| oldest            | 32u      | Age of the oldest honored object.            |
Packit 4e8bc4
| evictions         | on/off   | When off, LRU evictions are disabled.        |
Packit 4e8bc4
| domain_socket     | string   | Path to the domain socket (if any).          |
Packit 4e8bc4
| umask             | 32 (oct) | umask for the creation of the domain socket. |
Packit 4e8bc4
| growth_factor     | float    | Chunk size growth factor.                    |
Packit 4e8bc4
| chunk_size        | 32       | Minimum space allocated for key+value+flags. |
Packit 4e8bc4
| num_threads       | 32       | Number of threads (including dispatch).      |
Packit 4e8bc4
| stat_key_prefix   | char     | Stats prefix separator character.            |
Packit 4e8bc4
| detail_enabled    | bool     | If yes, stats detail is enabled.             |
Packit 4e8bc4
| reqs_per_event    | 32       | Max num IO ops processed within an event.    |
Packit 4e8bc4
| cas_enabled       | bool     | When no, CAS is not enabled for this server. |
Packit 4e8bc4
| tcp_backlog       | 32       | TCP listen backlog.                          |
Packit 4e8bc4
| auth_enabled_sasl | yes/no   | SASL auth requested and enabled.             |
Packit 4e8bc4
| item_size_max     | size_t   | maximum item size                            |
Packit 4e8bc4
| maxconns_fast     | bool     | If fast disconnects are enabled              |
Packit 4e8bc4
| hashpower_init    | 32       | Starting size multiplier for hash table      |
Packit 4e8bc4
| slab_reassign     | bool     | Whether slab page reassignment is allowed    |
Packit 4e8bc4
| slab_automove     | bool     | Whether slab page automover is enabled       |
Packit 4e8bc4
| slab_automove_ratio                                                         |
Packit 4e8bc4
|                   | float    | Ratio limit between young/old slab classes   |
Packit 4e8bc4
| slab_automove_window                                                        |
Packit 4e8bc4
|                   | 32u      | Internal algo tunable for automove           |
Packit 4e8bc4
| slab_chunk_max    | 32       | Max slab class size (avoid unless necessary) |
Packit 4e8bc4
| hash_algorithm    | char     | Hash table algorithm in use                  |
Packit 4e8bc4
| lru_crawler       | bool     | Whether the LRU crawler is enabled           |
Packit 4e8bc4
| lru_crawler_sleep | 32       | Microseconds to sleep between LRU crawls     |
Packit 4e8bc4
| lru_crawler_tocrawl                                                         |
Packit 4e8bc4
|                   | 32u      | Max items to crawl per slab per run          |
Packit 4e8bc4
| lru_maintainer_thread                                                       |
Packit 4e8bc4
|                   | bool     | Split LRU mode and background threads        |
Packit 4e8bc4
| hot_lru_pct       | 32       | Pct of slab memory reserved for HOT LRU      |
Packit 4e8bc4
| warm_lru_pct      | 32       | Pct of slab memory reserved for WARM LRU     |
Packit 4e8bc4
| hot_max_factor    | float    | Set idle age of HOT LRU to COLD age * this   |
Packit 4e8bc4
| warm_max_factor   | float    | Set idle age of WARM LRU to COLD age * this  |
Packit 4e8bc4
| temp_lru          | bool     | If yes, items < temporary_ttl use TEMP_LRU   |
Packit 4e8bc4
| temporary_ttl     | 32u      | Items with TTL < this are marked  temporary  |
Packit 4e8bc4
| idle_time         | 0        | Drop connections that are idle this many     |
Packit 4e8bc4
|                   |          | seconds (0 disables)                         |
Packit 4e8bc4
| watcher_logbuf_size                                                         |
Packit 4e8bc4
|                   | 32u      | Size of internal (not socket) write buffer   |
Packit 4e8bc4
|                   |          | per active watcher connected.                |
Packit 4e8bc4
| worker_logbuf_size| 32u      | Size of internal per-worker-thread buffer    |
Packit 4e8bc4
|                   |          | which the background thread reads from.      |
Packit 4e8bc4
| track_sizes       | bool     | If yes, a "stats sizes" histogram is being   |
Packit 4e8bc4
|                   |          | dynamically tracked.                         |
Packit 4e8bc4
| inline_ascii_response                                                       |
Packit 4e8bc4
|                   | bool     | Does nothing as of 1.5.15                    |
Packit 4e8bc4
| drop_privileges   | bool     | If yes, and available, drop unused syscalls  |
Packit 4e8bc4
|                   |          | (see seccomp on Linux, pledge on OpenBSD)    |
Packit 4e8bc4
|-------------------+----------+----------------------------------------------|
Packit 4e8bc4
Packit 4e8bc4
Packit 4e8bc4
Item statistics
Packit 4e8bc4
---------------
Packit 4e8bc4
CAVEAT: This section describes statistics which are subject to change in the
Packit 4e8bc4
future.
Packit 4e8bc4
Packit 4e8bc4
The "stats" command with the argument of "items" returns information about
Packit 4e8bc4
item storage per slab class. The data is returned in the format:
Packit 4e8bc4
Packit 4e8bc4
STAT items:<slabclass>:<stat> <value>\r\n
Packit 4e8bc4
Packit 4e8bc4
The server terminates this list with the line
Packit 4e8bc4
Packit 4e8bc4
END\r\n
Packit 4e8bc4
Packit 4e8bc4
The slabclass aligns with class ids used by the "stats slabs" command. Where
Packit 4e8bc4
"stats slabs" describes size and memory usage, "stats items" shows higher
Packit 4e8bc4
level information.
Packit 4e8bc4
Packit 4e8bc4
The following item values are defined as of writing.
Packit 4e8bc4
Packit 4e8bc4
Name                   Meaning
Packit 4e8bc4
------------------------------
Packit 4e8bc4
number                 Number of items presently stored in this class. Expired
Packit 4e8bc4
                       items are not automatically excluded.
Packit 4e8bc4
number_hot             Number of items presently stored in the HOT LRU.
Packit 4e8bc4
number_warm            Number of items presently stored in the WARM LRU.
Packit 4e8bc4
number_cold            Number of items presently stored in the COLD LRU.
Packit 4e8bc4
number_temp            Number of items presently stored in the TEMPORARY LRU.
Packit 4e8bc4
age_hot                Age of the oldest item in HOT LRU.
Packit 4e8bc4
age_warm               Age of the oldest item in WARM LRU.
Packit 4e8bc4
age                    Age of the oldest item in the LRU.
Packit 4e8bc4
mem_requested          Number of bytes requested to be stored in this LRU[*]
Packit 4e8bc4
evicted                Number of times an item had to be evicted from the LRU
Packit 4e8bc4
                       before it expired.
Packit 4e8bc4
evicted_nonzero        Number of times an item which had an explicit expire
Packit 4e8bc4
                       time set had to be evicted from the LRU before it
Packit 4e8bc4
                       expired.
Packit 4e8bc4
evicted_time           Seconds since the last access for the most recent item
Packit 4e8bc4
                       evicted from this class. Use this to judge how
Packit 4e8bc4
                       recently active your evicted data is.
Packit 4e8bc4
outofmemory            Number of times the underlying slab class was unable to
Packit 4e8bc4
                       store a new item. This means you are running with -M or
Packit 4e8bc4
                       an eviction failed.
Packit 4e8bc4
tailrepairs            Number of times we self-healed a slab with a refcount
Packit 4e8bc4
                       leak. If this counter is increasing a lot, please
Packit 4e8bc4
                       report your situation to the developers.
Packit 4e8bc4
reclaimed              Number of times an entry was stored using memory from
Packit 4e8bc4
                       an expired entry.
Packit 4e8bc4
expired_unfetched      Number of expired items reclaimed from the LRU which
Packit 4e8bc4
                       were never touched after being set.
Packit 4e8bc4
evicted_unfetched      Number of valid items evicted from the LRU which were
Packit 4e8bc4
                       never touched after being set.
Packit 4e8bc4
evicted_active         Number of valid items evicted from the LRU which were
Packit 4e8bc4
                       recently touched but were evicted before being moved to
Packit 4e8bc4
                       the top of the LRU again.
Packit 4e8bc4
crawler_reclaimed      Number of items freed by the LRU Crawler.
Packit 4e8bc4
lrutail_reflocked      Number of items found to be refcount locked in the
Packit 4e8bc4
                       LRU tail.
Packit 4e8bc4
moves_to_cold          Number of items moved from HOT or WARM into COLD.
Packit 4e8bc4
moves_to_warm          Number of items moved from COLD to WARM.
Packit 4e8bc4
moves_within_lru       Number of times active items were bumped within
Packit 4e8bc4
                       HOT or WARM.
Packit 4e8bc4
direct_reclaims        Number of times worker threads had to directly pull LRU
Packit 4e8bc4
                       tails to find memory for a new item.
Packit 4e8bc4
hits_to_hot
Packit 4e8bc4
hits_to_warm
Packit 4e8bc4
hits_to_cold
Packit 4e8bc4
hits_to_temp           Number of get_hits to each sub-LRU.
Packit 4e8bc4
Packit 4e8bc4
Note this will only display information about slabs which exist, so an empty
Packit 4e8bc4
cache will return an empty set.
Packit 4e8bc4
Packit 4e8bc4
* Items are stored in a slab that is the same size or larger than the
Packit 4e8bc4
  item.  mem_requested shows the size of all items within a
Packit 4e8bc4
  slab. (total_chunks * chunk_size) - mem_requested shows memory
Packit 4e8bc4
  wasted in a slab class.  If you see a lot of waste, consider tuning
Packit 4e8bc4
  the slab factor.
Packit 4e8bc4
Packit 4e8bc4
Packit 4e8bc4
Item size statistics
Packit 4e8bc4
--------------------
Packit 4e8bc4
CAVEAT: This section describes statistics which are subject to change in the
Packit 4e8bc4
future.
Packit 4e8bc4
Packit 4e8bc4
The "stats" command with the argument of "sizes" returns information about the
Packit 4e8bc4
general size and count of all items stored in the cache.
Packit 4e8bc4
WARNING: In versions prior to 1.4.27 this command causes the cache server to
Packit 4e8bc4
lock while it iterates the items. 1.4.27 and greater are safe.
Packit 4e8bc4
Packit 4e8bc4
The data is returned in the following format:
Packit 4e8bc4
Packit 4e8bc4
STAT <size> <count>\r\n
Packit 4e8bc4
Packit 4e8bc4
The server terminates this list with the line
Packit 4e8bc4
Packit 4e8bc4
END\r\n
Packit 4e8bc4
Packit 4e8bc4
'size' is an approximate size of the item, within 32 bytes.
Packit 4e8bc4
'count' is the amount of items that exist within that 32-byte range.
Packit 4e8bc4
Packit 4e8bc4
This is essentially a display of all of your items if there was a slab class
Packit 4e8bc4
for every 32 bytes. You can use this to determine if adjusting the slab growth
Packit 4e8bc4
factor would save memory overhead. For example: generating more classes in the
Packit 4e8bc4
lower range could allow items to fit more snugly into their slab classes, if
Packit 4e8bc4
most of your items are less than 200 bytes in size.
Packit 4e8bc4
Packit 4e8bc4
In 1.4.27 and after, this feature must be manually enabled.
Packit 4e8bc4
Packit 4e8bc4
A "stats" command with the argument of "sizes_enable" will enable the
Packit 4e8bc4
histogram at runtime. This has a small overhead to every store or delete
Packit 4e8bc4
operation. If you don't want to incur this, leave it off.
Packit 4e8bc4
Packit 4e8bc4
A "stats" command with the argument of "sizes_disable" will disable the
Packit 4e8bc4
histogram.
Packit 4e8bc4
Packit 4e8bc4
It can also be enabled at starttime with "-o track_sizes"
Packit 4e8bc4
Packit 4e8bc4
If disabled, "stats sizes" will return:
Packit 4e8bc4
Packit 4e8bc4
STAT sizes_status disabled\r\n
Packit 4e8bc4
Packit 4e8bc4
"stats sizes_enable" will return:
Packit 4e8bc4
Packit 4e8bc4
STAT sizes_status enabled\r\n
Packit 4e8bc4
Packit 4e8bc4
"stats sizes_disable" will return:
Packit 4e8bc4
Packit 4e8bc4
STAT sizes_status disabled\r\n
Packit 4e8bc4
Packit 4e8bc4
If an error happens, it will return:
Packit 4e8bc4
Packit 4e8bc4
STAT sizes_status error\r\n
Packit 4e8bc4
STAT sizes_error [error_message]\r\n
Packit 4e8bc4
Packit 4e8bc4
CAVEAT: If CAS support is disabled, you cannot enable/disable this feature at
Packit 4e8bc4
runtime.
Packit 4e8bc4
Packit 4e8bc4
Slab statistics
Packit 4e8bc4
---------------
Packit 4e8bc4
CAVEAT: This section describes statistics which are subject to change in the
Packit 4e8bc4
future.
Packit 4e8bc4
Packit 4e8bc4
The "stats" command with the argument of "slabs" returns information about
Packit 4e8bc4
each of the slabs created by memcached during runtime. This includes per-slab
Packit 4e8bc4
information along with some totals. The data is returned in the format:
Packit 4e8bc4
Packit 4e8bc4
STAT <slabclass>:<stat> <value>\r\n
Packit 4e8bc4
STAT <stat> <value>\r\n
Packit 4e8bc4
Packit 4e8bc4
The server terminates this list with the line
Packit 4e8bc4
Packit 4e8bc4
END\r\n
Packit 4e8bc4
Packit 4e8bc4
|-----------------+----------------------------------------------------------|
Packit 4e8bc4
| Name            | Meaning                                                  |
Packit 4e8bc4
|-----------------+----------------------------------------------------------|
Packit 4e8bc4
| chunk_size      | The amount of space each chunk uses. One item will use   |
Packit 4e8bc4
|                 | one chunk of the appropriate size.                       |
Packit 4e8bc4
| chunks_per_page | How many chunks exist within one page. A page by         |
Packit 4e8bc4
|                 | default is less than or equal to one megabyte in size.   |
Packit 4e8bc4
|                 | Slabs are allocated by page, then broken into chunks.    |
Packit 4e8bc4
| total_pages     | Total number of pages allocated to the slab class.       |
Packit 4e8bc4
| total_chunks    | Total number of chunks allocated to the slab class.      |
Packit 4e8bc4
| get_hits        | Total number of get requests serviced by this class.     |
Packit 4e8bc4
| cmd_set         | Total number of set requests storing data in this class. |
Packit 4e8bc4
| delete_hits     | Total number of successful deletes from this class.      |
Packit 4e8bc4
| incr_hits       | Total number of incrs modifying this class.              |
Packit 4e8bc4
| decr_hits       | Total number of decrs modifying this class.              |
Packit 4e8bc4
| cas_hits        | Total number of CAS commands modifying this class.       |
Packit 4e8bc4
| cas_badval      | Total number of CAS commands that failed to modify a     |
Packit 4e8bc4
|                 | value due to a bad CAS id.                               |
Packit 4e8bc4
| touch_hits      | Total number of touches serviced by this class.          |
Packit 4e8bc4
| used_chunks     | How many chunks have been allocated to items.            |
Packit 4e8bc4
| free_chunks     | Chunks not yet allocated to items, or freed via delete.  |
Packit 4e8bc4
| free_chunks_end | Number of free chunks at the end of the last allocated   |
Packit 4e8bc4
|                 | page.                                                    |
Packit 4e8bc4
| active_slabs    | Total number of slab classes allocated.                  |
Packit 4e8bc4
| total_malloced  | Total amount of memory allocated to slab pages.          |
Packit 4e8bc4
|-----------------+----------------------------------------------------------|
Packit 4e8bc4
Packit 4e8bc4
Packit 4e8bc4
Connection statistics
Packit 4e8bc4
---------------------
Packit 4e8bc4
The "stats" command with the argument of "conns" returns information
Packit 4e8bc4
about currently active connections and about sockets that are listening
Packit 4e8bc4
for new connections. The data is returned in the format:
Packit 4e8bc4
Packit 4e8bc4
STAT <file descriptor>:<stat> <value>\r\n
Packit 4e8bc4
Packit 4e8bc4
The server terminates this list with the line
Packit 4e8bc4
Packit 4e8bc4
END\r\n
Packit 4e8bc4
Packit 4e8bc4
The following "stat" keywords may be present:
Packit 4e8bc4
Packit 4e8bc4
|---------------------+------------------------------------------------------|
Packit 4e8bc4
| Name                | Meaning                                              |
Packit 4e8bc4
|---------------------+------------------------------------------------------|
Packit 4e8bc4
| addr                | The address of the remote side. For listening        |
Packit 4e8bc4
|                     | sockets this is the listen address. Note that some   |
Packit 4e8bc4
|                     | socket types (such as UNIX-domain) don't have        |
Packit 4e8bc4
|                     | meaningful remote addresses.                         |
Packit 4e8bc4
| listen_addr         | The address of the server. This field is absent      |
Packit 4e8bc4
|                     | for listening sockets.                               |
Packit 4e8bc4
| state               | The current state of the connection. See below.      |
Packit 4e8bc4
| secs_since_last_cmd | The number of seconds since the most recently        |
Packit 4e8bc4
|                     | issued command on the connection. This measures      |
Packit 4e8bc4
|                     | the time since the start of the command, so if       |
Packit 4e8bc4
|                     | "state" indicates a command is currently executing,  |
Packit 4e8bc4
|                     | this will be the number of seconds the current       |
Packit 4e8bc4
|                     | command has been running.                            |
Packit 4e8bc4
|---------------------+------------------------------------------------------|
Packit 4e8bc4
Packit 4e8bc4
The value of the "state" stat may be one of the following:
Packit 4e8bc4
Packit 4e8bc4
|----------------+-----------------------------------------------------------|
Packit 4e8bc4
| Name           | Meaning                                                   |
Packit 4e8bc4
|----------------+-----------------------------------------------------------|
Packit 4e8bc4
| conn_closing   | Shutting down the connection.                             |
Packit 4e8bc4
| conn_listening | Listening for new connections or a new UDP request.       |
Packit 4e8bc4
| conn_mwrite    | Writing a complex response, e.g., to a "get" command.     |
Packit 4e8bc4
| conn_new_cmd   | Connection is being prepared to accept a new command.     |
Packit 4e8bc4
| conn_nread     | Reading extended data, typically for a command such as    |
Packit 4e8bc4
|                | "set" or "put".                                           |
Packit 4e8bc4
| conn_parse_cmd | The server has received a command and is in the middle    |
Packit 4e8bc4
|                | of parsing it or executing it.                            |
Packit 4e8bc4
| conn_read      | Reading newly-arrived command data.                       |
Packit 4e8bc4
| conn_swallow   | Discarding excess input, e.g., after an error has         |
Packit 4e8bc4
|                | occurred.                                                 |
Packit 4e8bc4
| conn_waiting   | A partial command has been received and the server is     |
Packit 4e8bc4
|                | waiting for the rest of it to arrive (note the difference |
Packit 4e8bc4
|                | between this and conn_nread).                             |
Packit 4e8bc4
| conn_write     | Writing a simple response (anything that doesn't involve  |
Packit 4e8bc4
|                | sending back multiple lines of response data).            |
Packit 4e8bc4
|----------------+-----------------------------------------------------------|
Packit 4e8bc4
Packit Service aafb6d
TLS statistics
Packit Service aafb6d
--------------
Packit Service aafb6d
Packit Service aafb6d
TLS is a compile-time opt-in feature available in versions 1.5.13 and later.
Packit Service aafb6d
When compiled with TLS support and TLS termination is enabled at runtime, the
Packit Service aafb6d
following additional statistics are available via the "stats" command.
Packit Service aafb6d
Packit Service aafb6d
|--------------------------------+----------+--------------------------------|
Packit Service aafb6d
| Name                           | Type     | Meaning                        |
Packit Service aafb6d
|--------------------------------+----------+--------------------------------|
Packit Service aafb6d
| ssl_handshake_errors           | 64u      | Number of times the server has |
Packit Service aafb6d
|                                |          | encountered an OpenSSL error   |
Packit Service aafb6d
|                                |          | during handshake (SSL_accept). |
Packit Service aafb6d
| time_since_server_cert_refresh | 32u      | Number of seconds that have    |
Packit Service aafb6d
|                                |          | elapsed since the last time    |
Packit Service aafb6d
|                                |          | certs were reloaded from disk. |
Packit Service aafb6d
|--------------------------------+----------+--------------------------------|
Packit 4e8bc4
Packit 4e8bc4
Packit 4e8bc4
Other commands
Packit 4e8bc4
--------------
Packit 4e8bc4
Packit 4e8bc4
"flush_all" is a command with an optional numeric argument. It always
Packit 4e8bc4
succeeds, and the server sends "OK\r\n" in response (unless "noreply"
Packit 4e8bc4
is given as the last parameter). Its effect is to invalidate all
Packit 4e8bc4
existing items immediately (by default) or after the expiration
Packit 4e8bc4
specified.  After invalidation none of the items will be returned in
Packit 4e8bc4
response to a retrieval command (unless it's stored again under the
Packit 4e8bc4
same key *after* flush_all has invalidated the items). flush_all
Packit 4e8bc4
doesn't actually free all the memory taken up by existing items; that
Packit 4e8bc4
will happen gradually as new items are stored. The most precise
Packit 4e8bc4
definition of what flush_all does is the following: it causes all
Packit 4e8bc4
items whose update time is earlier than the time at which flush_all
Packit 4e8bc4
was set to be executed to be ignored for retrieval purposes.
Packit 4e8bc4
Packit 4e8bc4
The intent of flush_all with a delay, was that in a setting where you
Packit 4e8bc4
have a pool of memcached servers, and you need to flush all content,
Packit 4e8bc4
you have the option of not resetting all memcached servers at the
Packit 4e8bc4
same time (which could e.g. cause a spike in database load with all
Packit 4e8bc4
clients suddenly needing to recreate content that would otherwise
Packit 4e8bc4
have been found in the memcached daemon).
Packit 4e8bc4
Packit 4e8bc4
The delay option allows you to have them reset in e.g. 10 second
Packit 4e8bc4
intervals (by passing 0 to the first, 10 to the second, 20 to the
Packit 4e8bc4
third, etc. etc.).
Packit 4e8bc4
Packit 4e8bc4
"cache_memlimit" is a command with a numeric argument. This allows runtime
Packit 4e8bc4
adjustments of the cache memory limit. It returns "OK\r\n" or an error (unless
Packit 4e8bc4
"noreply" is given as the last parameter). If the new memory limit is higher
Packit 4e8bc4
than the old one, the server may start requesting more memory from the OS. If
Packit 4e8bc4
the limit is lower, and slabs_reassign+automove are enabled, free memory may
Packit 4e8bc4
be released back to the OS asynchronously.
Packit 4e8bc4
Packit 4e8bc4
The argument is in megabytes, not bytes. Input gets multiplied out into
Packit 4e8bc4
megabytes internally.
Packit 4e8bc4
Packit 4e8bc4
"version" is a command with no arguments:
Packit 4e8bc4
Packit 4e8bc4
version\r\n
Packit 4e8bc4
Packit 4e8bc4
In response, the server sends
Packit 4e8bc4
Packit 4e8bc4
"VERSION <version>\r\n", where <version> is the version string for the
Packit 4e8bc4
server.
Packit 4e8bc4
Packit 4e8bc4
"verbosity" is a command with a numeric argument. It always succeeds,
Packit 4e8bc4
and the server sends "OK\r\n" in response (unless "noreply" is given
Packit 4e8bc4
as the last parameter). Its effect is to set the verbosity level of
Packit 4e8bc4
the logging output.
Packit 4e8bc4
Packit 4e8bc4
"quit" is a command with no arguments:
Packit 4e8bc4
Packit 4e8bc4
quit\r\n
Packit 4e8bc4
Packit 4e8bc4
Upon receiving this command, the server closes the
Packit 4e8bc4
connection. However, the client may also simply close the connection
Packit 4e8bc4
when it no longer needs it, without issuing this command.
Packit 4e8bc4
Packit 4e8bc4
Security restrictions
Packit 4e8bc4
---------------------
Packit 4e8bc4
Packit 4e8bc4
In the debug build the following commands are available for testing the
Packit 4e8bc4
security restrictions:
Packit 4e8bc4
Packit 4e8bc4
"misbehave" is a command with no arguments:
Packit 4e8bc4
Packit 4e8bc4
misbehave\r\n
Packit 4e8bc4
Packit 4e8bc4
This command causes the worker thread to attempt a) opening a new socket, and
Packit 4e8bc4
b) executing a shell command. If either one is successful, an error is
Packit 4e8bc4
returned. Otherwise memcached returns OK.
Packit 4e8bc4
The check is available only in Linux builds with seccomp enabled.
Packit 4e8bc4
Packit 4e8bc4
Packit 4e8bc4
UDP protocol
Packit 4e8bc4
------------
Packit 4e8bc4
Packit 4e8bc4
For very large installations where the number of clients is high enough
Packit 4e8bc4
that the number of TCP connections causes scaling difficulties, there is
Packit 4e8bc4
also a UDP-based interface. The UDP interface does not provide guaranteed
Packit 4e8bc4
delivery, so should only be used for operations that aren't required to
Packit 4e8bc4
succeed; typically it is used for "get" requests where a missing or
Packit 4e8bc4
incomplete response can simply be treated as a cache miss.
Packit 4e8bc4
Packit 4e8bc4
Each UDP datagram contains a simple frame header, followed by data in the
Packit 4e8bc4
same format as the TCP protocol described above. In the current
Packit 4e8bc4
implementation, requests must be contained in a single UDP datagram, but
Packit 4e8bc4
responses may span several datagrams. (The only common requests that would
Packit 4e8bc4
span multiple datagrams are huge multi-key "get" requests and "set"
Packit 4e8bc4
requests, both of which are more suitable to TCP transport for reliability
Packit 4e8bc4
reasons anyway.)
Packit 4e8bc4
Packit 4e8bc4
The frame header is 8 bytes long, as follows (all values are 16-bit integers
Packit 4e8bc4
in network byte order, high byte first):
Packit 4e8bc4
Packit 4e8bc4
0-1 Request ID
Packit 4e8bc4
2-3 Sequence number
Packit 4e8bc4
4-5 Total number of datagrams in this message
Packit 4e8bc4
6-7 Reserved for future use; must be 0
Packit 4e8bc4
Packit 4e8bc4
The request ID is supplied by the client. Typically it will be a
Packit 4e8bc4
monotonically increasing value starting from a random seed, but the client
Packit 4e8bc4
is free to use whatever request IDs it likes. The server's response will
Packit 4e8bc4
contain the same ID as the incoming request. The client uses the request ID
Packit 4e8bc4
to differentiate between responses to outstanding requests if there are
Packit 4e8bc4
several pending from the same server; any datagrams with an unknown request
Packit 4e8bc4
ID are probably delayed responses to an earlier request and should be
Packit 4e8bc4
discarded.
Packit 4e8bc4
Packit 4e8bc4
The sequence number ranges from 0 to n-1, where n is the total number of
Packit 4e8bc4
datagrams in the message. The client should concatenate the payloads of the
Packit 4e8bc4
datagrams for a given response in sequence number order; the resulting byte
Packit 4e8bc4
stream will contain a complete response in the same format as the TCP
Packit 4e8bc4
protocol (including terminating \r\n sequences).