The client communicates with the server in lines of text through the tcp/udp protocol.
Memcached provides a set of commands, and operations on cached data items are done by executing a command.
Command items consist of the following:
a key
Arbitrary string, up to 250 bytes in length . ASCII mode without spaces or newlines
a 32 -bit tag value
Expiration
In seconds, 0 means never expire. up to 30 days
a 64 -bit CAS value
keep it unique
arbitrary data
represents the original data
CAS is optional and can be disabled with -C .
Most commands support the "noreply" mode. In general, this method should not be used because it cannot guarantee that the error response is in the same order as the request.
Order
Mainly include write, read, statistics
write command
set
The most commonly used command
Used for writing data, but also for updating. If the written data already exists, it is updated to overwrite the previously existing data.
If new data is written, the new data item written is at the top of the LRU .
add
Used to write data, but not update it. If the written data already exists, the update will not be performed, the write will fail, and the new data item written will be at the top of the LRU .
如果写入的数据已存在,将写入失败,add操作将无论如何把已存在的数据项提升到LRU的前端。
replace
用于写入数据,只用于当数据已存在,对数据进行替换更新。这个命令基本不用,提供这个命令主要出于协议完整性。
append
追加操作,只用于当数据已存在,在已存在的数据后面追加。
prepend
和append类似,但是在已存在的数据前面进行追加。
cas
这个也是用于写入数据,这个操作保证读到最新数据。保证并发更新的数据一致性。这里“保证读到最新数据”啥意思?你们自己理解吧。
读取命令
get
用于读取数据,可以传一个或多个key,返回所有存在的数据。
gets
用于读取数据,和get不一样,使用CAS。同时返回一个CAS标识。和cas操作一起使用时,如果gets操作返回的CAS标识已经变了,cas操作将不会写入这个数据。
delete
用于删除操作,如果该数据已存在,则删除。
incr
decr
用于加减操作,适用于64位整数或字符串形式的64位整数。不接受负值。如果操作的数据项的值不存在,则incr,decr操作将失败。
统计命令
stats
stats items
stats slabs
stats sizes
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->
flush_all