【memcached】memcached中flags欄位的作用
阿新 • • 發佈:2019-02-19
看了一下memcached的協議,是這樣定義一個item的:
Each item sent by the server looks like this:
VALUE <key> <flags> <bytes> [<cas unique>]\r\n
<data block>\r\n
- <key> is the key for the item being sent
- <flags> is the flags value set by the storage command
- <bytes> is the length of the data block to follow, *not* including
its delimiting \r\n
- <cas unique> is a unique 64-bit integer that uniquely identifies
this specific item.
- <data block> is the data for this item.
在memcached1.2.1之前為flags預留了16位,到了1.2.1以後預留了32位。對於伺服器端而言,並不清楚你設定這些標記的作用。它並不知道你的資料是壓縮過的,還是序列化儲存的。
其實這只是客戶端自己的一種定義,我們看Pecl的memcached模組的原始碼:
#define MMC_SERIALIZED 1
#define MMC_COMPRESSED 2
if (flags & MMC_COMPRESSED) {
unsigned long data_len;
if (!mmc_compress(&data, &data_len, value, value_len TSRMLS_CC)) {
/* mmc_server_seterror(mmc, "Failed to compress data", 0); */
return -1;
}
/* was enough space saved to motivate uncompress processing on get */
if (data_len < value_len * (1 - pool->min_compress_savings)) {
value = data;
value_len = data_len;
}
else {
flags &= ~MMC_COMPRESSED;
efree(data);
data = NULL;
}
}
當flags包含MMC_COMPRESSED就對資料進行壓縮處理。
也就是說,如果我們自己寫一個memcached的client,也可以定義出更多的格式,json,xml或者別的。
其它關於 flags的文章請看
Each item sent by the server looks like this:
VALUE <key> <flags> <bytes> [<cas unique>]\r\n
<data block>\r\n
- <key> is the key for the item being sent
- <flags> is the flags value set by the storage command
- <bytes> is the length of the data block to follow, *not* including
its delimiting \r\n
- <cas unique> is a unique 64-bit integer that uniquely identifies
this specific item.
- <data block> is the data for this item.
在memcached1.2.1之前為flags預留了16位,到了1.2.1以後預留了32位。對於伺服器端而言,並不清楚你設定這些標記的作用。它並不知道你的資料是壓縮過的,還是序列化儲存的。
其實這只是客戶端自己的一種定義,我們看Pecl的memcached模組的原始碼:
#define MMC_SERIALIZED 1
#define MMC_COMPRESSED 2
if (flags & MMC_COMPRESSED) {
unsigned long data_len;
if (!mmc_compress(&data, &data_len, value, value_len TSRMLS_CC)) {
/* mmc_server_seterror(mmc, "Failed to compress data", 0); */
return -1;
}
/* was enough space saved to motivate uncompress processing on get */
if (data_len < value_len * (1 - pool->min_compress_savings)) {
value = data;
value_len = data_len;
}
else {
flags &= ~MMC_COMPRESSED;
efree(data);
data = NULL;
}
}
當flags包含MMC_COMPRESSED就對資料進行壓縮處理。
也就是說,如果我們自己寫一個memcached的client,也可以定義出更多的格式,json,xml或者別的。
其它關於 flags的文章請看