protocol.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. specification:
  2. - https://github.com/memcached/memcached/blob/master/doc/protocol.txt
  3. - Expiration times:
  4. - Some commands involve a client sending some kind of expiration time (relative to an item or to
  5. an operation requested by the client) to the server.
  6. - In all such cases, the actual value sent may either be
  7. - Unix time (number of seconds since January 1, 1970, as a 32-bit value),
  8. - or a number of seconds starting from current time.
  9. - In the latter case, this number of seconds may not exceed 60*60*24*30 (number of seconds in 30
  10. days); if the number sent by a client is larger than that, the server will consider it to be
  11. real Unix time value rather than an offset from current time.
  12. - errors:
  13. - "ERROR\r\n": means the client sent a nonexistent command name.
  14. - "CLIENT_ERROR <error>\r\n": means some sort of client error in the input line, i.e. the input
  15. doesn't conform to the protocol in some way. <error> is a human-readable error string.
  16. - "SERVER_ERROR <error>\r\n": means some sort of server error prevents the server from carrying
  17. out the command. <error> is a human-readable error string. In cases of severe server errors,
  18. which make it impossible to continue serving the client (this shouldn't normally happen),
  19. the server will close the connection after sending the error line. This is the only case in
  20. which the server closes a connection to a client.
  21. - In the descriptions of individual commands below, these error lines are not again specifically
  22. mentioned, but clients must allow for their possibility.
  23. commands:
  24. - A command line always starts with the name of the command, followed by parameters (if any)
  25. delimited by whitespace.
  26. - Command names are lower-case and are case-sensitive.
  27. storage:
  28. - ask the server to store some data identified by a key.
  29. - The client sends a command line, and then a data block;
  30. - After that the client expects one line of response, which will indicate success or failure.
  31. - commands:
  32. basic commands:
  33. - "add|replace|set <key> <flags> <exptime> <bytes> [noreply]\r\n"
  34. - add: store the data under the key, but only if data for the key does not already exist
  35. - replace: store the data under the key, but only if data for the key already exist
  36. - set: store the data under the key
  37. update commands:
  38. - "append|prepend <key> <bytes> [noreply]\r\n"
  39. - append: add this data to an existing key after existing data (?)
  40. - prepend: add this data to an existing key before existing data (?)
  41. cas:
  42. - "cas <key> <flags> <exptime> <bytes> <cas unique> [noreply]\r\n"
  43. - check and set operation which means "store this data but only if no one else has updated
  44. since I last fetched it."
  45. - command format:
  46. <key>: the key under which the client asks to store the data
  47. <flags>: is an arbitrary 16-bit unsigned integer (written out in decimal) that the server stores
  48. along with the data and sends back when the item is retrieved. Clients may use this as a bit
  49. field to store data-specific information; this field is opaque to the server. Note that in
  50. memcached 1.2.1 and higher, flags may be 32-bits, instead of 16, but you might want to
  51. restrict yourself to 16 bits for compatibility with older versions.
  52. <exptime>: is expiration time.:
  53. - If it's 0, the item never expires (although it may be deleted from the cache to make place
  54. for other items).
  55. - If it's non-zero (either Unix time or offset in seconds from current time), it is guaranteed
  56. that clients will not be able to retrieve this item after the expiration time arrives
  57. (measured byserver time).
  58. - If a negative value is given the item is immediately expired.
  59. <bytes>:
  60. - the number of bytes in the data block to follow, *not* including the delimiting \r\n.
  61. - <bytes> may be zero (in which case it's followed by an empty data block).
  62. <cas unique>:
  63. - only used by the cas command
  64. - a unique 64-bit value of an existing entry.
  65. - Clients should use the value returned from the "gets" command when issuing "cas" updates.
  66. "noreply":
  67. - optional parameter instructs the server to not send the reply.
  68. - NOTE: if the request line is malformed, the server can't parse "noreply" option reliably.
  69. In this case it may send the error to the client, and not reading it on the client side will
  70. break things. Client should construct only valid requests.
  71. data:
  72. - After this line, the client sends the data block:
  73. - <data block>\r\n
  74. - <data block> is a chunk of arbitrary 8-bit data of length <bytes> from the previous line.
  75. - responses:
  76. - After sending the command line and the data block the client awaits the reply, which may be:
  77. - "STORED\r\n", to indicate success.
  78. - "NOT_STORED\r\n" to indicate the data was not stored, but not because of an error.
  79. This normally means that the condition for an "add" or a "replace" command wasn't met.
  80. - "EXISTS\r\n" to indicate that the item you are trying to store with a "cas" command has been
  81. modified since you last fetched it.
  82. - "NOT_FOUND\r\n" to indicate that the item you are trying to store with a "cas" command did
  83. not exist.
  84. retrieval:
  85. - ask the server to retrieve data corresponding to a set of keys (one or more keys in one
  86. request).
  87. - The client sends a command line, which includes all the requested keys;
  88. - after that for each item the server finds it sends to the client one response line with
  89. information about the item, and one data block with the item's data;
  90. - this continues until the server finished with the "END" response line.
  91. - commands:
  92. - "get|gets <key>*\r\n"
  93. - <key>* means one or more key strings separated by whitespace.
  94. - After this command, the client expects zero or more items, each of which is received as a text
  95. line followed by a data block. After all the items have been transmitted, the server sends the
  96. string "END\r\n" to indicate the end of response.
  97. - Each item sent by the server looks like this:
  98. - VALUE <key> <flags> <bytes> [<cas unique>]\r\n
  99. - <data block>\r\n
  100. - <key> is the key for the item being sent
  101. - <flags> is the flags value set by the storage command
  102. - <bytes> is the length of the data block to follow, *not* including its delimiting \r\n
  103. - <cas unique> is a unique 64-bit integer that uniquely identifies this specific item.
  104. - <data block> is the data for this item.
  105. - If some of the keys appearing in a retrieval request are not sent back by the server in the
  106. item list this means that the server does not hold items with such keys (because they were
  107. never stored, or stored but deleted to make space for more items, or expired, or explicitly
  108. deleted by a client).
  109. other:
  110. - don't involve unstructured data.
  111. - In all of them, the client sends one command line, and expects (depending on the
  112. command) either one line of response, or several lines of response ending with "END" on the last
  113. line.
  114. - commands:
  115. - delete:
  116. - "delete <key> [noreply]\r\n"
  117. - <key> is the key of the item the client wishes the server to delete
  118. - "noreply" optional parameter instructs the server to not send the reply.
  119. - The response line to this command can be one of:
  120. - "DELETED\r\n" to indicate success
  121. - "NOT_FOUND\r\n" to indicate that the item with this key was not found.
  122. - See the "flush_all" command below for immediate invalidation of all existing items.
  123. - increment/decrement:
  124. - change data for some item in-place, incrementing or decrementing it.
  125. - "incr|decr <key> <value> [noreply]\r\n"
  126. - <key> is the key of the item the client wishes to change
  127. - <value> is the amount by which the client wants to increase/decrease the item. It is a
  128. decimal representation of a 64-bit unsigned integer.
  129. - "noreply" optional parameter instructs the server to not send the reply.
  130. - The response will be one of:
  131. - "NOT_FOUND\r\n" to indicate the item with this value was not found
  132. - "<value>\r\n" , where <value> is the new value of the item's data, after the
  133. increment/decrement operation was carried out.
  134. - The data for the item is treated as decimal representation of a 64-bit unsigned integer.
  135. - If the current data value does not conform to such a representation, the incr/decr commands
  136. return an error
  137. - The item must already exist for incr/decr to work; these commands won't pretend that a
  138. non-existent key exists with value 0; instead, they will fail.
  139. - Underflow in the "decr" command is caught: if a client tries to decrease the value below 0,
  140. the new value will be 0.
  141. - Overflow in the "incr" command will wrap around the 64 bit mark.
  142. - Decrementing a number such that it loses length isn't guaranteed to decrement its returned
  143. length. The number MAY be space-padded at the end, but this is purely an implementation
  144. optimization, so you also shouldn't rely on that.
  145. - quit:
  146. - touch:
  147. - update the expiration time of an existing item without fetching it.
  148. - "touch <key> <exptime> [noreply]\r\n"
  149. - "<exptime>"
  150. - Expiration time, same as with the storage commands (set/add/etc).
  151. - This replaces the existing expiration time. If an existing item were to expire in 10
  152. seconds, but then was touched with an expiration time of "20", the item would then expire
  153. in 20 seconds.
  154. - The response line to this command can be one of:
  155. - "TOUCHED\r\n" to indicate success
  156. - "NOT_FOUND\r\n" to indicate that the item with this key was not found.
  157. versions:
  158. - Some notable changes... see Changelog for full list
  159. - 2003 / 1.1.10: added flush_all command
  160. - 2006 / 1.2.0: added UDP transport
  161. - 2007 / 1.2.1: <flags> switched from a 16-bit value to a 32-bit value
  162. - 2007 / 1.2.2: added verbosity command
  163. - 2007 / 1.2.4:
  164. - added cas and gets commands
  165. - incr/decr values switched from 32-bit to 64-bit values
  166. - 2009 / 1.2.7: increment/decrement no longer treats a non-integer value as 0 but returns an error
  167. -