当前位置:网站首页>How to use redis to solve concurrency problems
How to use redis to solve concurrency problems
2022-06-28 07:55:00 【star++】
summary
redis As a cache component , Generally speaking, it is used to cache the data of our program . So there may be two aspects of concurrency , One is redis Data concurrency in cache , One is the data concurrency of business programs .
redis Cache data concurrency problem
scene 1:
What we do is a blog system , You need to collect and count the likes of each article , It is a concurrent behavior for multiple users to like at the same time ,
Generally speaking, there is a data concurrency problem at this time . The initial number of likes for the article is 0, At this time, Zhang San and Li Si are writing an article at the same time
Like it , The initial values obtained are 0, All the likes are +1, Update back at this time , The number of likes is 1 了 .
Solution : Use it directly redis Of incr Command statistics is enough . because redis Is a single thread processing instructions ( lock ), And then this incr Instruction is
Single instruction read / write is an atomic operation ( visibility , Atomicity ), Therefore, there is no data concurrency coverage problem .
scene 2:
Suppose our blog system has a recommendation function , When users like , You also need to tag a user who likes a certain type of blog , next time
You can recommend similar articles to users . This time involves two operations , Number of likes +
边栏推荐
- Investment transaction and settlement of the fund
- 2021 programming language ranking summary
- Software design of resistance test board
- QT -- communication protocol
- HJ base conversion
- golang gin框架进行分块传输
- 自动化测试的生命周期是什么?
- Kubernetes deploys a secret pit where thanos ruler sends repeated alarms
- 7-1 understand everything
- HJ质数因子
猜你喜欢
Disposition Flex
PLC -- Notes
推荐系统系列精讲(第五讲): 排序模型的调优实践
sql主从复制搭建
Section 8: DMA of zynq
Software design of resistance test board
MySQL installation and environment variable configuration
[ thanos源码分析系列 ]thanos query组件源码简析
Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
sql分析(查询截取分析做sql优化)
随机推荐
pip 更新到最新的版本
Today's notes 22/1/7
Recommended system series (Lecture 5): Optimization Practice of sorting model
Upgrade HDP spark to spark 2.4.8 without upgrading ambari
协程、asyncio、异步编程
Flex layout
Ambari (VIII) --- ambari integrated impala document (valid for personal test)
Conversion between HJ integer and IP address
Section VI UART of zynq
flex布局
Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
Study notes 22/1/11
7-2 Finnish wooden chess structure Sorting
分析 NFT 项目的 5 个指标
Is it safe to open an account on Dongfang fortune
HJ字符串排序
SOC serial port configuration
Software design of resistance test board
Study notes 22/1/17
Ambari (VI) -- ambari API use