This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 160
ApsaraCache_for_memcache_document
kingpeterpaule edited this page Oct 20, 2017
·
1 revision
在memcache中,每一个key都有CAS和FLAG属性,其中CAS相当于是每个数据的版本号,该版本号随着对数据的修改而单调递增。为了在ApsaraCache中支持每个key的CAS和FLAG属性,在实现中采用如下的数据结构来存储每一个key的CAS,FLAG,value:
typedef struct memcachedItem {
uint64_t cas;
uint32_t flag;
char buf[];
} memcachedItem;
我们将key对应的value,CAS和FLAG打包存储在memcachedItem结构中,然后将该结构存储在redis的基本存储结构robj的ptr中. 这样做主要是基于两点考虑:(1)不用增加新的数据类型,rdb和aof实现后向兼容。(2)主从同步可以完全复用redis的主从同步方式,不需要额外的修改支持。
在持久化和双副本的实现上,我们保持了和redis一致的方式:即同时支持AOF和RDB快照两种方式。在实现上,实例是以memcache通信协议接收请求,在对请求接收,处理完毕后,我们将memcache协议的命令转换成相应的redis的命令和协议,然后以redis的协议方式写AOF和做主从同步;
- text命令
get gets set add replace append prepend cas delete quit incr decr touch flush_all version
- binary命令
Byte | Meaning |
---|---|
0x00 | Get |
0x01 | Set |
0x02 | Add |
0x03 | Replace |
0x04 | Delete |
0x05 | Increment |
0x06 | Decrement |
0x07 | Quit |
0x08 | Flush |
0x09 | GetQ |
0x0a | No-op |
0x0b | Version |
0x0c | GetK |
0x0d | GetKQ |
0x0e | Append |
0x0f | Prepend |
0x10 | Stat |
0x11 | SetQ |
0x12 | AddQ |
0x13 | ReplaceQ |
0x14 | DeleteQ |
0x15 | IncrementQ |
0x16 | DecrementQ |
0x17 | QuitQ |
0x18 | FlushQ |
0x19 | AppendQ |
0x1a | PrependQ |
0x1b | Verbosity * |
0x1c | Touch * |
0x1d | GAT * |
0x1e | GATQ * |
0x20 | SASL list mechs |
0x21 | SASL Auth |