当前位置:网站首页>Redis(七)优化建议
Redis(七)优化建议
2022-07-01 03:36:00 【解梦者】
1、缓存与数据库不一致怎么办
假设采用的主从结构的、读写分离的数据库。
如果一个线程A先删除缓存数据,然后将数据写入到主库中,这个时候,主库和从库同步没有完成,线程B从缓存当中读取数据失败,从从库当中读取到旧数据,然后更新至缓存,这个时候,缓存当中的就是旧的数据。
发生上述不一致的原因在于:主从库数据不一致问题,加入了缓存之后,主从不一致的时间被拉长了。
处理思路:在从库有数据更新之后,将缓存当中的数据也同时进行更新,即当从库发生了数据更新之后,向缓存发出删除,淘汰这段时间写入的旧数据。
2、主从数据库不一致如何解决
场景描述:对于主从库,读写分离,如果主从库更新同步有时差,就会导致主从数据库的不一致。
处理思路:
- 1、忽略这个数据不一致,在数据一致性要求不高的业务下,未必需要实时一致性。
- 2、强制读主库,使用一个高可用的主库,数据库读写都在主库,添加一个缓存,提升数据读取的性能。
- 3、选择性读主库,增加一个缓存,用来记录必须读主库的数据,明确将哪个库、哪个表、哪个主键作为缓存的key,设置缓存失效的时间为主从库同步的时间。如果缓存当中有个这个数据,直接读取主库,如果缓存当中没有这个主键,就到对应的从库中读取。
3、Redis常见的性能问题和解决方案
1、Master最好不要做持久化工作,如RDB内存快照和AOF日志文件。
2、如果数据比较重要,某个Slave开启AOF备份,策略设置成每秒同步一次。
3、尽量避免在压力大的主库上增加从库。
4、主从复制不要采取网状结构,尽量是线性结构,Master <— Slave1 <— Slave2等等。
边栏推荐
猜你喜欢

程序员女友给我做了一个疲劳驾驶检测

The difference between MFC for static libraries and MFC for shared libraries

Valentine's Day is nothing.

Review column - message queue
![[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline](/img/af/4498382bc47d8c9ae41c407b9d1265.png)
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline

Idea plug-in backup table

MFC窗口滚动条用法

SEM of C language_ Tvariable type

431. 将 N 叉树编码为二叉树 DFS

Quickly filter data such as clock in time and date: Excel filter to find whether a certain time point is within a certain time period
随机推荐
[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation
205. 同构字符串
Volley parsing data shows networking failure
【TA-霜狼_may-《百人计划》】2.2 模型与材质空间
不同性能测试工具的并发模式
Gorilla/mux framework (RK boot): RPC error code design
Future of NTF and trends in 2022
Jeecgboot output log, how to use @slf4j
392. 判断子序列
Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
Review column - message queue
[shortcut key]
Bilinear upsampling and f.upsample in pytorch_ bilinear
Pytorch training deep learning network settings CUDA specified GPU visible
TEC: Knowledge Graph Embedding with Triple Context
Use of comment keyword in database
What happens when a function is called before it is declared in C?
Deep learning | rnn/lstm of naturallanguageprocessing
The difference between MFC for static libraries and MFC for shared libraries
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline