当前位置:网站首页>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 +边栏推荐
- Evaluation of inverse Polish expression < difficulty coefficient >
- Is it reliable to open a new bond registration account? Is it safe?
- 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
- Rediscluster cluster mode capacity expansion node
- No suspense about the No. 1 Internet company overtime table
- Spark 离线开发框架设计与实现
- A single node obtains the lock lock of the order number
- Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
- GPIO configuration of SOC
- 剑指Offer||:链表(简单)
猜你喜欢

Static resource compression reduces bandwidth pressure and increases access speed

sql分析(查询截取分析做sql优化)

Section Xi. Axi of zynq_ Use of DMA

SOC clock configuration

Airflow2.x distributed deployment DAG execution failure log cannot be obtained normally
![[ thanos源码分析系列 ]thanos query组件源码简析](/img/e4/2a87ef0d5cee0cc1c1e1b91b6fd4af.png)
[ thanos源码分析系列 ]thanos query组件源码简析

GoLand IDE and delve debug Go programs in kubernetes cluster

What is EC blower fan?

Upgrade HDP spark to spark 2.4.8 without upgrading ambari

8 figures | analyze Eureka's first synchronization registry
随机推荐
Hash slot of rediscluster cluster cluster implementation principle
分析 NFT 项目的 5 个指标
基金的投资交易与结算
No suspense about the No. 1 Internet company overtime table
Study notes 22/1/18
【尚品汇】项目笔记
flex布局
Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
Flex layout
Sentinel mechanism of redis cluster
What is the lifecycle of automated testing?
golang gin框架进行分块传输
Software testing and quality final review
Hj21 simple password
Is it safe for flush to open an account online
股票炒股注册开户靠谱吗?安全吗?
Configuring MySQL multi instance master-slave synchronization for Linux
HJ整数与IP地址间的转换
Redis one master multi slave cluster setup
大型项目中的Commit Message规范化控制实现