Memcached 连接

用 nc / telnet 连 memcached,理解文本协议。

Beginner
Key PointsMemcached 用极简文本行协议:一行命令、一行数据、一行响应,肉眼可读。

用 nc 连接

Shell
# 进入交互:每行输入一条命令,回车看响应
nc 127.0.0.1 11211
Output
(连接成功,光标停在新行,等待输入命令)

协议长这样

Shell
set foo 0 900 5
hello
Output
STORED

set foo 0 900 5: command, key, flag, TTL 900s, value length 5; the next line is the 5-byte value hello. Server replies STORED.

flag is an opaque integer for the client (e.g. marking encoding); memcached stores it untouched and returns it with the value. TTL 0 means 'never expire' (still evictable by LRU).

Friends & Partners