File: memcache.txt

package info (click to toggle)
nutcracker 0.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,208 kB
  • ctags: 1,273
  • sloc: ansic: 13,846; sh: 741; makefile: 98; python: 42
file content (123 lines) | stat: -rw-r--r-- 3,601 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
- ascii:

- Storage Commands (set, add, replace, append, prepend, cas):

  set <key> <flags> <expiry> <datalen> [noreply]\r\n<data>\r\n
  add <key> <flags> <expiry> <datalen> [noreply]\r\n<data>\r\n
  replace <key> <flags> <expiry> <datalen> [noreply]\r\n<data>\r\n
  append <key> <flags> <expiry> <datalen> [noreply]\r\n<data>\r\n
  prepend <key> <flags> <expiry> <datalen> [noreply]\r\n<data>\r\n

  cas <key> <flags> <expiry> <datalen> <cas> [noreply]\r\n<data>\r\n

  where,
  <flags>   - uint32_t : data specific client side flags
  <expiry>  - uint32_t : expiration time (in seconds)
  <datalen> - uint32_t : size of the data (in bytes)
  <data>    - uint8_t[]: data block
  <cas>     - uint64_t

- Retrival Commands (get, gets):

  get <key>\r\n
  get <key> [<key>]+\r\n

  gets <key>\r\n
  gets <key> [<key>]+\r\n

- Delete Command (delete):

  delete <key> [noreply]\r\n

- Arithmetic Commands (incr, decr):

  incr <key> <value> [noreply]\r\n
  decr <key> <value> [noreply]\r\n

  where,
  <value> - uint64_t

- Misc Commands (quit)

  quit\r\n
  flush_all [<delay>] [noreply]\r\n
  version\r\n
  verbosity <num> [noreply]\r\n

- Statistics Commands

  stats\r\n
  stats <args>\r\n

- Error Responses:

  ERROR\r\n
  CLIENT_ERROR [error]\r\n
  SERVER_ERROR [error]\r\n

  where,
  ERROR means client sent a non-existent command name
  CLIENT_ERROR means that command sent by the client does not conform to the protocol
  SERVER_ERROR means that there was an error on the server side that made processing of the command impossible

- Storage Command Responses:

  STORED\r\n
  NOT_STORED\r\n
  EXISTS\r\n
  NOT_FOUND\r\n

  where,
  STORED indicates success.
  NOT_STORED indicates the data was not stored because condition for an add or replace wasn't met.
  EXISTS indicates that the item you are trying to store with a cas has been modified since you last fetched it.
  NOT_FOUND indicates that the item you are trying to store with a cas does not exist.

- Delete Command Response:

  NOT_FOUND\r\n
  DELETED\r\n

- Retrival Responses:

  END\r\n
  VALUE <key> <flags> <datalen> [<cas>]\r\n<data>\r\nEND\r\n
  VALUE <key> <flags> <datalen> [<cas>]\r\n<data>\r\n[VALUE <key> <flags> <datalen> [<cas>]\r\n<data>]+\r\nEND\r\n

- Arithmetic Responses:

  NOT_FOUND\r\n
  <value>\r\n

  where,
  <value> - uint64_t : new key value after incr or decr operation

- Statistics Response
  [STAT <name> <value>\r\n]+END\r\n

- Misc Response

  OK\r\n
  VERSION <version>\r\n

- Notes:
  - set always creates mapping irrespective of whether it is present on not.
  - add, adds only if the mapping is not present
  - replace, only replaces if the mapping is present
  - append and prepend command ignore flags and expiry values
  - noreply instructs the server to not send the reply even if there is an error.
  - decr of 0 is 0, while incr of UINT64_MAX is 0
  - maximum length of the key is 250 characters
  - expiry of 0 means that item never expires, though it could be evicted from the cache
  - non-zero expiry is either unix time (# seconds since 01/01/1970) or,
    offset in seconds from the current time (< 60 x 60 x 24 x 30 seconds = 30 days)
  - expiry time is with respect to the server (not client)
  - <datalen> can be zero and when it is, the <data> block is empty.

- Thoughts:
  - ascii protocol is easier to debug - think using strace or tcpdump to see
    protocol on the wire, Or using telnet or netcat or socat to build memcache
    requests and responses
    http://stackoverflow.com/questions/2525188/are-binary-protocols-dead

  - http://news.ycombinator.com/item?id=1712788