当前位置:网站首页>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 +边栏推荐
- Installing redis on Linux
- Block transmission by golang gin framework
- HJ进制转换
- 异或的应用。(提取出数字中最右侧的1,面试中经常用的到)
- flex布局
- Is it safe to open an account on Dongfang fortune
- flutter 实现摇一摇功能
- Soft test -- software designer -- database design of afternoon questions
- Static resource compression reduces bandwidth pressure and increases access speed
- 【尚品汇】项目笔记
猜你喜欢

本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献

Section 9: dual core startup of zynq

Uninstall and reinstall the latest version of MySQL database. The test is valid

The solution of "user account control to continue, please enter administrator user name and password" appears in win10 Professional Edition

Ambari (VII) --- ambari integrated hue4.2 document (valid for personal test)

Kubernetes cluster command line tool kubectl

kubernetes集群命令行工具kubectl

kubelet垃圾(退出的容器和未使用的镜像)回收源码分析

Generation and verification of JWT token

Rediscluster cluster mode capacity expansion node
随机推荐
SOC serial port configuration
Source code analysis of kubernetes' process of deleting pod
HJ质数因子
Helloword routine for ROS
Software testing and quality final review
Unity-UI-shadow组件
Airflow2.x distributed deployment DAG execution failure log cannot be obtained normally
Is it reliable to open an account by digging money? Is it safe?
es数据导出csv文件
Dbeaver 22.1.1 release, visual database management platform
sql分析(查询截取分析做sql优化)
ZYNQ_ IIC read / write m24m01 record board status
Section 8: DMA of zynq
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
Sentinel mechanism of redis cluster
A single node obtains the lock lock of the order number
asp. Net datalist to display product information and pictures
kubernetes集群命令行工具kubectl
Redis implements distributed locks
Section VI UART of zynq