forked from memcached/memcached
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinary-protocol-plan.txt
66 lines (43 loc) · 2.15 KB
/
binary-protocol-plan.txt
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
Notes regarding the proposed binary protocol from Facebook's hosted
memcached hackathon on 2007-07-09:
REQUEST STRUCTURE:
* Magic byte / version
* Cmd byte
* Key len byte (if no key, 0)
* Reserved byte (should be 0)
* 4 byte opaque id. (will be copied back in response; means nothing to server)
* 4 byte body length (network order; not including 12 byte header)
[ cmd-specific fixed-width fields ]
* key, if key length above is non-zero.
[ cmd-specific variable-width field ]
RESPONSE STRUCTURE:
* Magic byte / version (different from req's magic byte/version, to distinguish
that it's a response for, say, protocol analyzers)
* cmd byte (same as response it goes to)
* err code byte (0 on success, else errcode. hit bit set if fatal/non-normal error)
* Reserved byte (should be 0)
* 4 byte opaque id copied back from response
* 4 byte body length (network order; not including 12 byte header)
[cmd-specific body]
COMMANDS: (for cmd byte)
get - single key get (no more multi-get; clients should pipeline)
getq - like get, but quiet. that is, no cache miss, return nothing.
Note: you're not guaranteed a response to a getq cache hit until
you send a non-getq command later, which uncorks the
server which bundles up IOs to send to the client in one go.
Note: clients should implement multi-get (still important for
reducing network roundtrips!) as n pipelined requests, the
first n-1 being getq, the last being a regular
get. that way you're guaranteed to get a response, and
you know when the server's done. you can also do the naive
thing and send n pipelined gets, but then you could potentially
get back a lot of "NOT_FOUND!" error code packets.
alternatively, you can send 'n' getqs, followed by an 'echo'
or 'noop' command.
delete
set/add/replace
cmd-specific fixed-width fields for set/add/replace:
* 4 byte expiration time
* 4 byte flags
(the 4 byte length is inferred from the total body length,
subtracting (keylen + body length))