Memcached gets 命令

gets 是带 CAS 版本号的 get,配合 cas 做乐观锁。

Beginner
Key Pointsgets 返回末尾多一个 cas 唯一标识,写回时当作 cas 的参数。

用法

Shell
set k 0 0 1
9
gets k
Output
STORED
VALUE k 0 1 42
9
END

The trailing 42 in VALUE k 0 1 42 is the cas token. Remember it and use cas k 0 0 1 42 to write back; if changed meanwhile, the token differs and cas returns EXISTS.

gets and get differ only by the token, nearly identical cost. Use gets+cas whenever you need a concurrency-safe write; get is enough for reads.

Friends & Partners