当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
【MySQL8入门到精通】基础篇- Linux系统静默安装MySQL,跨版本升级
What are the advantages and disadvantages of Unity shader forge and the built-in shader graph?
实验8 DNS解析
C语言教程(二)-printf及c自带的数据类型
C语言实验一 熟悉C程序的环境
110 MySQL interview questions and answers (continuously updated)
剑指offer基础版 ----- 第25天
数据库上机实验7 数据库设计
Why use Flink and how to get started with Flink?
三子棋讲解(C语言)
如何将项目部署到服务器上(全套教程)
【LeetCode-SQL每日一练】——2. 第二高的薪水
[Detailed explanation of ORACLE Explain]
面试官,不要再问我三次握手和四次挥手
Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
剑指offer基础版 ----- 第28天
Interviewer, don't ask me to shake hands three times and wave four times again
剑指offer基础版 ---- 第26天
基于flask的三方登陆的流程
MySQL (updating)