新聞中心
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.

站在用戶的角度思考問題,與客戶深入溝通,找到順慶網(wǎng)站設(shè)計(jì)與順慶網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、主機(jī)域名、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋順慶地區(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)網(wǎng)、IDC服務(wù)、應(yīng)用軟件開發(fā)、網(wǎng)站建設(shè)推廣的公司,為客戶提供互聯(lián)網(wǎng)基礎(chǔ)服務(wù)!
創(chuàng)新互聯(lián)(www.cdcxhl.com)提供簡單好用,價(jià)格厚道的香港/美國云服務(wù)器和獨(dú)立服務(wù)器。創(chuàng)新互聯(lián)——四川成都IDC機(jī)房服務(wù)器托管/機(jī)柜租用。為您精選優(yōu)質(zhì)idc數(shù)據(jù)中心機(jī)房租用、服務(wù)器托管、機(jī)柜租賃、大帶寬租用,高電服務(wù)器托管,算力服務(wù)器租用,可選線路電信、移動(dòng)、聯(lián)通機(jī)房等。
分享名稱:Redis中控制逐出策略的實(shí)現(xiàn)(redis逐出策略)
本文鏈接:http://www.dlmjj.cn/article/djceogp.html


咨詢
建站咨詢
