当前位置:网站首页>What happens when redis runs out of memory
What happens when redis runs out of memory
2022-06-25 05:55:00 【HelloWorld forever】
1. Memory recovery
Use redis We need to set the validity period for some key value pairs ,redis Through 4 A separate command to set the expiration time for a key value :
(1)expire key ttl : take key The expiration time for is set to ttl second
(2)pexpire key ttl : take key The expiration time of the value is set to ttl millisecond
(3)expireat key timestamp : take key The expiration time of is set to the specified timestamp Number of seconds
(4)pexpireat key timestamp : take key The expiration time of the value is set to the specified timestamp Number of milliseconds
Whatever command you use ,redis The bottom floor is all through pexpireat To set the expiration time
View remaining expiration time : Can pass ttl and pttl Two commands to view
ttl key return key Seconds left to expire
pttl key return key The number of milliseconds remaining to expire
If the expiration time is not set, this 2 All commands return -1 , If an illegal expiration time is set , All return to -2.
2. Expiration strategy
If you delete an expired key , We have three strategies
(1) Delete regularly : Set a timer for each key , Once the expiration time is up , Delete the key . This strategy is memory friendly , But yes. CPU unfriendly , Because each timer will occupy a certain amount of CPU resources .
(2) Lazy deletion : No matter whether the key has expired or not, it will not be deleted automatically , Wait until each time you get the key to determine whether it is expired , Delete the key if it is out of date , Otherwise, it returns the value of the key . This strategy is not memory friendly , It can waste a lot of memory .
(3) Scan regularly : The system scans regularly at regular intervals , Delete the expired key when it is found . This strategy is relatively a compromise between the above two strategies , It should be noted that the regular frequency should be well controlled according to the actual situation , One drawback of using this scheme is that keys that have expired may also be returned .
stay Redis in , The choice is strategy (2) And strategy (3) Comprehensive use of , however redis The regular scan of will only scan the key with expiration time set , Because the key to set the expiration time Redis Will be stored separately , So you don't have to scan all the keys :
typedef struct redisDb{
dict *dict ; // All key value pairs
dict * expires; // Set the key value pair of expiration time
dict * blocking_keys ;// blocked key
dict * watched_keys; //WATCHED keys
}
Redis Of 8 Kind of elimination strategy
First redis A parameter is provided maxmemory To configure the redis Maximum memory used :maxmemory <bytes> Or by order config set maxmemory 1GB To dynamically modify . If the parameter is not set , So in 32 Bit in the operating system Redis Use... At most 3GB Memory , And in the 64 There are no restrictions in the bit operating system .
Redis Provided in 8 Kind of elimination strategy , You can use the parameter maxmemory-policy To configure :

ttl: Set the expiration time of key in , Those with less time left will be eliminated first .
lru: Least recently used key, Priority to be eliminated .
lfu: The least visited recently key, Priority to be eliminated .
random: Randomly eliminate the contents of memory .
noeviction: Can no longer write Redis, Does not process the contents of memory , Is the default elimination strategy .
边栏推荐
- Only these four instructions are required to operate SQL data
- Code learning-cvpr2020 unsupervised domain adaptive semantic segmentation: intra advance
- Pat 1045 quick sort
- Differences and connections between sap ui5 and openui5
- Summary of 6 common methods of visual deep learning model architecture
- JSON Library Tutorial from scratch (III): parsing strings, learning and sorting notes
- Deep learning non local neural networks
- Synchonized introduction
- SAP ui5 beginner tutorial No. 27 - unit test tool quNit introduction trial version for SAP ui5 application
- Trouble of setting table property to null
猜你喜欢

Semantic segmentation cvpr2019-advance: advantageous enterprise minimization for domain adaptation in semantic segmentation

Getting started with mongodb

Create a complete binary tree in array order

Unsupervised domain adaptation in semantic segmentation:a review unsupervised domain adaptation in semantic segmentation: a review
Introduction to the main features of kyma when the cloud native application runs
Vscode voice notes to enrich information (medium)

Depth of binary tree

"APEC industry +" biov Tech talks about the cross-border of Chinese biotechnology enterprises and "Pratt & Whitney Kangyu" | apec-hub public welfare

Excel splits a worksheet into multiple worksheets according to conditions, and how to split multiple worksheets into independent tables

ArcGIS Engine + Visual Studio installation tutorial
随机推荐
MySQL transaction learning notes (I) first encounter
Aiot project that is an introduction to the basics of the Internet of things and can be implemented in practice
Which securities company is good for opening a mobile account? Is it safe to open a mobile account?
Leetcode topic [array] -36- effective Sudoku
Part 33 of SAP ui5 application development tutorial - trial version of responsiveness of SAP ui5 applications
Websocket in the promotion of vegetable farmers
[OSPF routing calculation (class I LSA router, class II LSA network, and class III LSA sum net)] -20211228-30
What is hybrid web containers for SAP ui5
05 virtual machine stack
SAP ui5 date type sap ui. model. type. Analysis of date parsing format
Go implements LRU cache
Day21 JMeter usage basis
Semantic segmentation cvpr2020 unsupervised intra domain adaptation for semantic segmentation through self supervision
Code learning-cvpr2020 unsupervised domain adaptive semantic segmentation: intra advance
Common cluster deployment schemes in redis
Feignclient reported an error npe:null
Learn the interface test, see it is very good, and make a note
ArcGIS Engine + Visual Studio installation tutorial
Monkey test of APP automation
Depth of binary tree