当前位置:网站首页>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 +边栏推荐
- Airflow2.1.1 summary of the pits stepped on in actual combat!!
- SOC timer and interrupt configuration
- NDK cross compilation
- Kubernetes理论基础
- Study notes 22/1/10
- Evaluation of inverse Polish expression < difficulty coefficient >
- 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进制转换
- Makefile
- Cloud native: cloud computing technology is upgraded again to open an era of comprehensive cloud development
猜你喜欢

软件测试与质量期末复习

Source code analysis of kubernetes' process of deleting pod

No suspense about the No. 1 Internet company overtime table

kubelet驱逐机制的源码分析

剑指Offer||:链表(简单)

A single node obtains the lock lock of the order number

SOC timer and interrupt configuration

Kubernetes cluster command line tool kubectl

asp. Net registration page

es6箭头函数中return的用法
随机推荐
HJ character count
HJ成绩排序
"Three routines" of digital collection market
HJ进制转换
Update pip to the latest version
Understanding of OPC protocol
kubelet驱逐机制的源码分析
分析 NFT 项目的 5 个指标
kubelet垃圾(退出的容器和未使用的镜像)回收源码分析
What is EC blower fan?
Cloud native: cloud computing technology is upgraded again to open an era of comprehensive cloud development
HJ字符串排序
Section 8: DMA of zynq
Section VI UART of zynq
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
HJ delete the character with the least number of occurrences in the string
golang gin框架进行分块传输
Is it reliable to open an account by digging money? Is it safe?
大型项目中的Commit Message规范化控制实现
asp. Net datalist when there are multiple data displays