当前位置:网站首页>Redis (IV) - delete policy
Redis (IV) - delete policy
2022-06-30 18:02:00 【Zhaoliwen is a pig】
Redis( Four )—— Deletion policy
List of articles
1、 Data deletion strategy
- Delete regularly
- Lazy deletion
- Delete periodically
The storage structure of timeliness data
- Redis Data in , stay expire Is stored in it as a hash . Its value Is the address of the data in memory ,filed Is the corresponding life cycle

The goal of the data deletion strategy
In memory footprint and CPU Find a way between occupation Balance , Taking care of one thing and losing the other will result in the whole redis Performance degradation , Even cause server downtime or memory leakage
2、 Three deletion strategies
Delete regularly
- Create a timer , When key Set an expiration time , And when the expiration time arrives , By timer task Execute now Delete key
- advantage : To save memory , Then delete , Free up unnecessary memory quickly
- shortcoming :CPU Under great pressure , No matter what CPU How high is the load at this time , All occupied CPU, It will affect redis Server response time and instruction throughput
- summary : Trade processor performance for storage ( Time for space )
Lazy deletion
- Data arrival expiration time , Don't deal with it . The next time you access the data
- If not expired , Return the data
- Found expired , Delete , Return does not exist
- advantage : save CPU performance , Delete when you find that you have to delete
- shortcoming : There's a lot of memory pressure , Data that has occupied memory for a long time
- summary : Swapping memory for processor performance ( Change space for time )
Delete periodically

- Periodic polling redis Time sensitive data in the library , use The strategy of random extraction , Use the proportion of expired data to control the frequency of deletion
- characteristic 1:CPU Performance occupancy settings have peaks , The detection frequency can be customized
- characteristic 2: Memory pressure is not great , Cold data that has occupied memory for a long time will be continuously cleaned up
- summary : Periodically spot check storage space ( Random sampling , Focus on spot check )
3、 The eviction algorithm
When new data enters redis when , What if there's not enough memory ?
- Redis Using memory to store data , Before executing every command , Would call freeMemoryIfNeeded() Check if there is enough memory . If the memory does not meet the minimum storage requirements for newly added data ,redis To temporarily delete some data and clean up the storage space for the current instruction . The strategy for cleaning up data is called The eviction algorithm
- Be careful : The process of evicting data is not 100% Can clean up enough available memory space , If not, repeat . After trying all the data , If the requirement of memory cleaning cannot be met , An error message will appear .
Related configurations that affect data eviction
Maximum available memory
maxmemoryThe proportion of physical memory occupied , The default value is 0, Means unrestricted . In the production environment, set according to the demand , Usually set at 50% above .
Select the number of data to be deleted each time
maxmemory-samplesData selection does not scan the entire database , Leading to serious performance consumption , Reduce read and write performance . Therefore, the method of randomly obtaining data is adopted as the data to be detected and deleted
Deletion policy
maxmemory-policyAfter reaching the maximum memory , The strategy of deleting the selected data
Related configurations that affect data eviction

LRU: The longest unused data
LFU: The least used data in a period of time
Data eviction policy configuration basis
- Use INFO command Output monitoring information , The query cache hit and miss The number of times , Tune according to business needs Redis To configure

边栏推荐
- Servlet operation principle_ API details_ Advanced path of request response construction (servlet_2)
- 现在玩期货需要注意什么,在哪里开户比较安全,我第一次接触
- Interview shock 60: what will cause MySQL index invalidation?
- NFT铸造交易平台开发详情
- Cloud practice of key business migration of Internet of things by well-known Internet housing rental service companies
- Rainbow Brackets 插件的快捷键
- Thinking on large file processing (upload, download)
- Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, is building an open source ecological road
- 新技能:通过代码缓存加速 Node.js 的启动
- Post MSF infiltration summary
猜你喜欢

Cloud practice of key business migration of Internet of things by well-known Internet housing rental service companies

阿里云ECS导入本地,解决部署的问题
![[Netease Yunxin] playback demo build: unable to convert parameter 1 from](/img/6e/41e1eafd4c863c9e5f3a545b69a257.png)
[Netease Yunxin] playback demo build: unable to convert parameter 1 from "asyncmodalrunner *" to "std:: nullptr\u T"**

Bridge emqx cloud data to AWS IOT through the public network

Design and principle of tubes responsive data system

Splitting.js文本标题缓慢加载js特效

Daily question brushing record (IX)

Small Tools(3) 集成Knife4j3.0.3接口文档

4年工作经验,多线程间的5种通信方式都说不出来,你敢信?

5g has been in business for three years. Where will innovation go in the future?
随机推荐
Interview shock 60: what will cause MySQL index invalidation?
每日面试1题-如何防止CDN防护被绕过
Key to understanding the trend of spot Silver
MSF后渗透总结
分享 5 大常用的特征选择方法,机器学习入门必看!!!
Cloud practice of key business migration of Internet of things by well-known Internet housing rental service companies
巴比特 | 元宇宙每日必读:未成年人打赏后要求退款,虚拟主播称自己是大冤种,怎么看待这个监管漏洞?...
DeFi借贷协议机制对比:Euler、Compound、Aave和Rari Capital
What did Tongji and Ali study in the CVPR 2022 best student thesis award? This is an interpretation of yizuo
.NET ORM框架HiSql实战-第一章-集成HiSql
大文件处理(上传,下载)思考
Synchronized summary
Splitting. JS text title slow loading JS effect
Nft: unlimited possibilities to open the era of encryption Art
基于SSM的新闻管理系统
What will be the game changes brought about by the meta universe?
Radio and television 5g officially set sail, attracting attention on how to apply the golden band
联想“双平台”运维解决方案 助力智慧医疗行业智慧管理能力全面提升
canvas鼠标控制重力js特效
Small tools (3) integration knife4j3.0.3 interface document