当前位置:网站首页>Redis memory obsolescence strategy
Redis memory obsolescence strategy
2022-06-12 05:41:00 【Xicai pengyuyan】
stay redid Used as a cache , When out of memory ,Redis Cache according to the configuration keys, Ensure that subsequent writes can succeed .
Memory maintenance solution
redis The maximum memory size is not set in the configuration of
If Redis The maximum memory size is not set or is set to 0, stay 64 Under the operating system Redis Do not limit the size of memory used , stay 32 Bit operating system is the most commonly used 3/4 Memory space
Memory operation command :
config get maxmemory : View maximum memory
config set maxmemory value : Set size
info memory : View the current Redis Memory usage command 
The main memory maintenance schemes are expiration strategy and memory elimination strategy
Expiration policy users process expired cache data
The memory obsolescence policy is used to Data requiring additional space when memory space is insufficient
Expiration strategy
redis Processing of expired data in , There are usually three ways :
1、 Timed expiration : Set the expiration time for each key Need to build a timer , When the expiration time is reached, it will be cleared immediately . This method is memory friendly , Yes CPU No optimization , It will take up a lot of CPU Resources to process expired data
2、 Inertia expires : Only when visiting one key when , To judge key Is it overdue , The scheme maximizes the savings CPU resources , But it will occupy memory resources ( Yes CPU friendly , Not memory friendly )
3、 Expire regularly : Every once in a while , Will scan certain data expires Some data in the dictionary , And clear the expired data
expires The dictionary will save all data that sets the expiration time .
Memory retirement strategy
When there is not enough memory ( Memory usage has exceeded mexmemory Parameter setting value is ), You need to process newly written data that requires extra space
volatile-lru: From the dataset that sets the expiration time (expries) Select the least recently used data to eliminate
volatile-ttl: From the dataset that sets the expiration time (expires) The data to be expired will be eliminated ,ttl The larger the value of, the more priority is to be eliminated
volatile-random: Set expiration time from dataset (expries) Randomly selected data in
allkeys-lru: From the data set (dict) Select the least recently used data in , The data to be eliminated by this strategy is all key Set , Not expired key
allkeys-random: From the data set (dict) Choose any data to eliminate
noeviction: It is forbidden to delete data , When out of memory , The new write operation will report an error , The request can proceed , Ensure that the inserted data will not be lost
The main strategy : It is divided into LRU Eliminate 、TTL Eliminate 、Random Eliminate
LRU Strategy ( Recently at least use ), The core idea , If the data has been accessed recently , Then the probability of being visited in the future will be higher
TTL Strategy : stay Redis Data set that sets the expiration time in expries Pick data from , according to ttl Expiration time for obsolescence , The higher the value, the earlier the elimination
Random strategy : Delete the random data in the data set
LFU Strategy :Redis 4.0 New policy in ,( Recently at least use ) The core idea : If the data is rarely accessed in the recent period of time , So it's less likely that the data will be accessed in the future , therefore , When the space is full , The data with the lowest access frequency will be eliminated first
LRU And LFU Is different :LRU Is the least recently used page replacement algorithm (Least Recently Used), That is, the first to eliminate the longest unused pages !LFU Is the most recently used page replacement algorithm (Least Frequently Used), That is, eliminate the least visited pages in a given period of time !
边栏推荐
- 44. a digit in a sequence of digits
- Codis 3. X expansion and contraction
- 虚函数与纯虚函数的关系
- 网络加速谁更猛?CDN领域再现新王者
- 57 - II. Continuous positive sequence with sum s
- Caused by: org. h2.jdbc. JdbcSQLSyntaxErrorException: Table “USER“ already exists; SQL statement:
- 62. the last number left in the circle
- Introduction to redis cluster
- Identification of campus green plants based on tensorflow
- @Configurationproperties value cannot be injected
猜你喜欢

Word frequency statistics using Jieba database

Available RTMP and RTSP test addresses of the public network (updated in March, 2021)

Codis 3. X expansion and contraction

Selenium crawler automatically captures TOEFL test position of NEEA website

国企为什么要上市

March 4, 2021

yolov5

Chapter 8 - structure

个人申请OV类型SSL证书
![[gin] gin framework for golang web development](/img/15/68c4fd217555f940b3cd3d10fcd54f.jpg)
[gin] gin framework for golang web development
随机推荐
38. 外观数列
Redis cluster cluster capacity expansion and data migration
16. Somme des trois plus proches
62. the last number left in the circle
Caused by: org. h2.jdbc. JdbcSQLSyntaxErrorException: Table “USER“ already exists; SQL statement:
Flex / fixed Upper, Middle and Lower (Mobile end)
17. print from 1 to the maximum n digits
March 4, 2021
公司注册认缴资金多久
关于架构(排名不分先后)
Test work summary - performance test related issues
16. sum of the nearest three numbers
Why should state-owned enterprises go public
How Wireshark decrypts WiFi data packets
Role and understanding of proc/cmdline
什么是工程预付款
60. points of N dice
Automated testing - Po mode / log /allure/ continuous integration
Nature | make an account of the new crown casualties in the world
Kubernetes certificate online update