当前位置:网站首页>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 +边栏推荐
- 基金的投资交易与结算
- Ambari (VI) -- ambari API use
- 自动化测试的生命周期是什么?
- Section 5: zynq interrupt
- Idea package together, using compact middle packages to solve &
- sql主从复制搭建
- Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers
- HJ明明的随机数
- ZYNQ_ IIC read / write m24m01 record board status
- asp. Net datalist when there are multiple data displays
猜你喜欢

8 figures | analyze Eureka's first synchronization registry

ACM笔记

Section Xi. Axi of zynq_ Use of DMA

flex布局

Analyze 5 indicators of NFT project

kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑

MySQL installation and environment variable configuration

At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions

Unity-UI-shadow组件

推荐系统系列精讲(第五讲): 排序模型的调优实践
随机推荐
Redis implements distributed locks
7-2 Finnish wooden chess structure Sorting
asp. Net registration page
Section 8: DMA of zynq
券商注册开户靠谱吗?安全吗?
Open62541 import nodeset file directly
GoLand IDE and delve debug Go programs in kubernetes cluster
Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers
Uninstall and reinstall the latest version of MySQL database. The test is valid
Update pip to the latest version
Idea package together, using compact middle packages to solve &
Flutter realizes the function of "shake"
No suspense about the No. 1 Internet company overtime table
HJ prime factor
Ambari (IX) --- use expect to realize no interaction in ambri server setup phase (valid for personal test)
Host is not allowed to connect to this MySQL server
HJ删除字符串中出现次数最少的字符
sql主从复制搭建
Unity UI shadow component
kubernetes集群命令行工具kubectl