Memcached replace 命令
replace 仅当 key 已存在时才更新。
Key Pointsreplace 与 add 相反:key 不存在就失败,存在才覆盖。
用法
Shell
set k 0 0 3
abc
replace k 0 0 3
xyz
get k
replace missing 0 0 3
xyzOutput
STORED
STORED
VALUE k 0 3
xyz
END
NOT_STOREDreplace returns NOT_STORED for missing keys. Use set for 'upsert', replace for 'update only if exists', add for 'insert only if absent' — their existence semantics are complementary.用法
Shell
set k 0 0 3
abc
replace k 0 0 3
xyz
get k
replace missing 0 0 3
xyzOutput
STORED
STORED
VALUE k 0 3
xyz
END
NOT_STOREDreplace 对不存在的 key 返回 NOT_STORED。想「有就改、没有就建」用 set;想「只改已有」用 replace;想「只建没有」用 add——三者的存在性语义正好互补。