当前位置:网站首页>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等等。
边栏推荐
- Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
- Asgnet paper and code interpretation 2
- Unexpected token o in JSON at position 1, JSON parsing problem
- [TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
- 389. 找不同
- 168. excel table column name
- 在线公网安备案保姆级教程【伸手党福利】
- The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
- Processing of menu buttons on the left and contents on the right of the background system page, and double scrolling appears on the background system page
- Cygwin的下载和安装配置
猜你喜欢

TEC: Knowledge Graph Embedding with Triple Context

不同性能测试工具的并发模式

使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况

整合阿里云短信的问题:无法从静态上下文中引用非静态方法

【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算
![[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle](/img/94/99090ea91082a385968e071ef3766c.png)
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
![Pyramid scene parsing network [pspnet] thesis reading](/img/05/4645c8a595083479dee6835620335d.png)
Pyramid scene parsing network [pspnet] thesis reading

Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly

Blueprism registration, download and install -rpa Chapter 1
![[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation](/img/4e/8cf60bc816441967c04f97c64685a1.png)
[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation
随机推荐
Promql select time series
【EI会议】2022年国际土木与海洋工程联合会议(JCCME 2022)
431. encode n-ary tree as binary tree DFS
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
72. edit distance
Use of comment keyword in database
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
205. isomorphic string
214. 最短回文串
访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
166. fractions to decimals
【TA-霜狼_may-《百人計劃》】1.2.1 向量基礎
Leetcode:829. 连续整数求和
[EI conference] 2022 international joint civil and Offshore Engineering Conference (jccme 2022)
392. 判断子序列
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
AfxMessageBox和MessageBox的用法
在 C 中声明函数之前调用函数会发生什么?
10. regular expression matching
[reach out to Party welfare] developer reload system sequence