当前位置:网站首页>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 +边栏推荐
- "Three routines" of digital collection market
- kubernetes集群命令行工具kubectl
- HJ21 简单密码
- Study notes 22/1/19 and 22/1/20
- HJ成绩排序
- 云原生:云计算技术再次升级 开启全面云开发时代
- Is it reliable to open an account by digging money? Is it safe?
- Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
- ACM笔记
- 挖财注册开户靠谱吗?安全吗?
猜你喜欢

8 figures | analyze Eureka's first synchronization registry

Block transmission by golang gin framework

A single node obtains the lock lock of the order number

Section VI UART of zynq

ACM笔记

Airflow2.1.1 summary of the pits stepped on in actual combat!!

软件测试与质量期末复习

Kubernetes theoretical basis
![[thanos source code analysis series]thanos query component source code analysis](/img/e4/2a87ef0d5cee0cc1c1e1b91b6fd4af.png)
[thanos source code analysis series]thanos query component source code analysis

Introduction and several months' experience of extending the solution thanos of Prometheus
随机推荐
flutter 实现摇一摇功能
剑指Offer||:链表(简单)
Uninstall and reinstall the latest version of MySQL database. The test is valid
Is it safe for flush to open an account online
安全培训是员工最大的福利!2022新员工入职安全培训全员篇
ZYNQ_ IIC read / write m24m01 record board status
Configuring MySQL multi instance master-slave synchronization for Linux
Leetcode learning records
Unity-UI-shadow组件
How to configure DDR3 of dm8148
Is it reliable for securities companies to register and open accounts? Is it safe?
Understanding of OPC protocol
HJ字符个数统计
HJ score ranking
Today's notes 22/1/7
Explanation and application of instr() function in Oracle
What is EC blower fan?
HJ delete the character with the least number of occurrences in the string
Study notes 22/1/10
Investment transaction and settlement of the fund