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.
站在用户的角度思考问题,与客户深入沟通,找到顺庆网站设计与顺庆网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站设计、成都网站建设、企业官网、英文网站、手机端网站、网站推广、主机域名、虚拟空间、企业邮箱。业务覆盖顺庆地区。
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.
成都创新互联科技有限公司,是一家专注于互联网、IDC服务、应用软件开发、网站建设推广的公司,为客户提供互联网基础服务!
创新互联(www.cdcxhl.com)提供简单好用,价格厚道的香港/美国云服务器和独立服务器。创新互联——四川成都IDC机房服务器托管/机柜租用。为您精选优质idc数据中心机房租用、服务器托管、机柜租赁、大带宽租用,高电服务器托管,算力服务器租用,可选线路电信、移动、联通机房等。
网站栏目:Redis中控制逐出策略的实现(redis逐出策略)
转载来于:http://www.mswzjz.cn/qtweb/news37/39137.html
攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能