Using the TCP Text Protocol


When communicating with memcached, you can connect to the server using the port configured for the server. You can open a connection with the server without requiring authorization or login. As soon as you have connected, you can start to send commands to the server. When you have finished, you can terminate the connection without sending any specific disconnection command. Clients are encouraged to keep their connections open to decrease latency and improve performance.

Data is sent to the memcached server in two forms:

Both text lines (commands and responses) and unstructured data are always terminated with the string \r\n. Because the data being stored may contain this sequence, the length of the data (returned by the client before the unstructured data is transmitted should be used to determine the end of the data.

Commands to the server are structured according to their operation:

For reference, a list of the different commands supported and their formats is provided below.

Table 14.1. memcached Command Reference

Command Command Formats
set set key flags exptime length, set key flags exptime length noreply
add add key flags exptime length, add key flags exptime length noreply
replace replace key flags exptime length, replace key flags exptime length noreply
append append key length, append key length noreply
prepend prepend key length, prepend key length noreply
cas cas key flags exptime length casunique, cas key flags exptime length casunique noreply
get get key1 [key2 ... keyn]
gets
delete delete key, delete key noreply, delete key expiry, delete key expiry noreply
incr incr key, incr key noreply, incr key value, incr key value noreply
decr decr key, decr key noreply, decr key value, decr key value noreply
stat stat, stat name, stat name value

When sending a command to the server, the response from the server is one of the settings in the following table. All response values from the server are terminated by \r\n:

Table 14.2. memcached Protocol Responses

Retornar