新聞中心
Redis is an open source, networked memory data structure store, widely used for distributed caching, database storage and message queueing. By taking advantage of the widely adopted key-value storage system, it can quickly process large amounts of data and mntn the high performance results. When the system’s memory gets too full and cannot be serviced by the memory avlable, it’s time to put into action eviction policies that control the ejection of entries from the data store.

站在用戶的角度思考問題,與客戶深入溝通,找到順慶網站設計與順慶網站推廣的解決方案,憑借多年的經驗,讓設計與互聯(lián)網技術結合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網站設計、成都網站建設、企業(yè)官網、英文網站、手機端網站、網站推廣、主機域名、虛擬空間、企業(yè)郵箱。業(yè)務覆蓋順慶地區(qū)。
There are two types of eviction strategies for Redis, which are based on the algorithms used. The first is known as the LFU (Least Frequently Used), and the second as the LRU (Least Recently Used). Both algorithms rely on information stored in memory such as the frequency of data access, time of the last access, data size, and so on, to determine the entry that should be evicted.
The LFU algorithm takes into account the frequency of access of keys. The least frequently accessed key will be identified and evicted first, so that newer entries can be cached. The following example shows a simple implementation of this algorithm:
// LFU eviction policy
FUNCTION evict_LFU() {
/* Use AE algorithm to traverse the list of keys and find the key which was accessed least frequently */
RedisModule_Scan AUX;
RedisModule_InitScan(&aux);
long minval = INT_MAX;
const char* minkey;
while (RedisModule_Next(&aux,&minkey, &minval) == REDISMODULE_OK){
if (minval
minkeyval = minval;
}
}
RedisModule_FreeScan(&aux);
removeKey(minkey);
}
The LRU algorithm, on the other hand, takes into account the time of last access of keys. The least recently used key will be identified and evicted first. This algorithm is more accurate and precise in determining the entry that should be removed. The following example shows a simple implementation of this algorithm:
// LRU eviction policy
FUNCTION evict_LRU() {
/* Initialize an aux scan and LRU double link list */
RedisModule_Scan aux;
RedisModule_LRU *lru;
RedisModule_InitScan(&aux);
RedisModule_InitLRU(&lru);
while (RedisModule_Next(&aux, &key, &value) == REDISMODULE_OK) {
RedisModule_LRU_Update(lru, key);
}
RedisModule_FreeScan(&aux);
const char* minkey;
RedisModule_LRU_GetFirst(lru, &minkey);
removeKey(minkey);
}
Whichever eviction policy is used, the implementation of it is critical in ensuring that the system performs at optimum levels by intelligently managing the memory space. Furthermore, depending on the usage scenario, different eviction policies can be enabled or disabled to get the best performance out of Redis.
成都創(chuàng)新互聯(lián)科技有限公司,是一家專注于互聯(lián)網、IDC服務、應用軟件開發(fā)、網站建設推廣的公司,為客戶提供互聯(lián)網基礎服務!
創(chuàng)新互聯(lián)(www.cdcxhl.com)提供簡單好用,價格厚道的香港/美國云服務器和獨立服務器。創(chuàng)新互聯(lián)——四川成都IDC機房服務器托管/機柜租用。為您精選優(yōu)質idc數(shù)據中心機房租用、服務器托管、機柜租賃、大帶寬租用,高電服務器托管,算力服務器租用,可選線路電信、移動、聯(lián)通機房等。
本文題目:Redis中控制逐出策略的實現(xiàn)(redis逐出策略)
路徑分享:http://fisionsoft.com.cn/article/djceogp.html


咨詢
建站咨詢
