当前位置:网站首页>Redis first meeting
Redis first meeting
2022-07-31 05:34:00 【The flowers are blooming in the south of the city^】
What are the advantages and disadvantages of Redis
Advantages:
- lIn-memory database, fast read and write speed
- lSupport data persistence for easy backup and recovery
- lSupports simple transactions
- lRich data types
- lSupport master-slave replication, sentinel mechanism
Disadvantages:
- lData is stored in memory and is easily lost.
- l When used as a cache, there is a problem of inconsistency with the database data
- lavalanche problem, cache breakdown problem, cache penetration problem
Why use Redis for caching?
Cache is divided into local cache and distributed cache.Distributed caches such as redis or memcached are used. In the case of multiple instances, each instance shares a cache of data, and the cache is consistent.
Why is Redis so fast
1) Pure memory operation
Redis stores data in memory, so it is not limited by the hard disk I/O speed when reading and writing data, so it is fast
2)Single thread operation
Single thread can avoid unnecessary switching between threads and resource preemption
What is the persistence mechanism of Redis?Advantages and disadvantages of each?
RDB: RDB is the default persistence method of Redis.The data in the memory is saved to the hard disk in the form of snapshots according to a certain period of time.The period of the snapshot is defined by the save parameter in the configuration file.
AOF: Persistence is to record each write command executed by Redis to a separate log file, and restore data to the file in the Redis log when restarting.
When both methods are enabled at the same time, Redis will give priority to AOF recovery for data recovery.
A comparison of the two types of persistence?
AOF files are updated more frequently than RDBs, and AOF is preferred to restore data.
AOF is more secure and bigger than RDB
RDB performance is better than AOF
If both are configured with AOF first
There are usually three types of expiration policies:
Timed Expiration: A timer needs to be created for each key whose expiration time is set, and it will be cleared immediately when the expiration time is reached.This strategy can immediately clear the expired data, which is very friendly to memory; however, it will take up a lot of CPU resources to process the expired data, thus affecting the response time and throughput of the cache.
Lazy Expiration: Only when a key is accessed will it be judged whether the key has expired, and if it expires, it will be cleared.In extreme cases, a large number of expired keys may not be accessed again, so they will not be cleared, occupying a lot of memory.
Regular scan: At regular intervals, the keys in the expires dictionary will be scanned, and the expired keys will be cleared.This strategy is a compromise between the first two.By adjusting the time interval of scheduled scans and the limited time-consuming of each scan, the CPU and memory resources can be optimally balanced under different circumstances.
边栏推荐
猜你喜欢
随机推荐
pytorch中的一维、二维、三维卷积操作
Simple command of mysql
对list集合进行分页,并将数据显示在页面中
面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
剑指offer专项突击版 --- 第 3 天
110 MySQL interview questions and answers (continuously updated)
基于flask的三方登陆的流程
tf.keras.utils.pad_sequences()
.NET-9. A mess of theoretical notes (concepts, ideas)
Flask-based three-party login process
Refinement of the four major collection frameworks: Summary of List core knowledge
tf.keras.utils.get_file()
MySQL (updating)
[MQ I can speak for an hour]
Sword Point Offer Special Assault Edition ---- Day 1
Unity mobile game performance optimization series: performance tuning for the CPU side
剑指offer专项突击版 ---- 第 6 天
The interviewer asked me how to divide the database and the table?Fortunately, I summed up a set of eight-part essays







