当前位置:网站首页>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等等。
边栏推荐
- 复习专栏之---消息队列
- 187. repeated DNA sequences
- 8. string conversion integer (ATOI)
- Valentine's Day is nothing.
- 208. implement trie (prefix tree)
- The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
- 187. 重复的DNA序列
- Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
- 静态库使用MFC和共享库使用MFC的区别
- [EI search] important information conference of the 6th International Conference on materials engineering and advanced manufacturing technology (meamt 2022) in 2022 website: www.meamt Org meeting time
猜你喜欢
The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
整合阿里云短信的问题:无法从静态上下文中引用非静态方法
5. [WebGIS practice] software operation - service release and permission management
Appium fundamentals of automated testing - basic principles of appium
Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
Bilinear upsampling and f.upsample in pytorch_ bilinear
访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
Blueprism registration, download and install -rpa Chapter 1
Appium自动化测试基础 — APPium基本原理
4. [WebGIS practice] software operation chapter - data import and processing
随机推荐
How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
171. Excel 表列序号
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
IPv4 and IPv6, LAN and WAN, gateway, public IP and private IP, IP address, subnet mask, network segment, network number, host number, network address, host address, and IP segment / number - what does
[EI search] important information conference of the 6th International Conference on materials engineering and advanced manufacturing technology (meamt 2022) in 2022 website: www.meamt Org meeting time
[TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
jeecgboot输出日志,@Slf4j的使用方法
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture
431. encode n-ary tree as binary tree DFS
程序员女友给我做了一个疲劳驾驶检测
[TA frost wolf \u may - "hundred people plan"] 2.1 color space
不同性能测试工具的并发模式
Explain spark operation mode in detail (local+standalone+yarn)
Sort linked list (merge sort)
The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
409. longest palindrome
Database DDL (data definition language) knowledge points
6. Z 字形变换
JMeter login failure, extracting login token, and obtaining token problem solving
Error: plug ins declaring extensions or extension points must set the singleton directive to true