Redis中控制逐出策略的实现(redis逐出策略)

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逐出策略)
链接URL:http://bzwzjz.com/article/djceogp.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 重庆网站制作 企业网站设计 app网站建设 成都网站设计制作公司 企业网站建设 成都网站制作 网站建设 成都商城网站建设 移动网站建设 重庆网站建设 成都定制网站建设 企业手机网站建设 网站建设公司 自适应网站建设 网站建设 成都网站建设流程 响应式网站设计 营销型网站建设 高端网站设计 营销网站建设 成都响应式网站建设 网站制作