当前位置:网站首页>PHP redis makes high burst spike
PHP redis makes high burst spike
2022-06-13 06:09:00 【Listen to the years】
Why do you say redis It can support high burst ?
Click to see why redis Can support high burst
Concrete realization
public function index13(UserService $userService)
{
// monitor goods_num Commodity inventory , If at update time , The inventory of goods has changed ( Modified by other processes ), Will not be updated successfully
Redis::watch('goods_num');
$goods_num = Redis::get('goods_num');
if($goods_num > 0)
{
$result = Redis::transaction(function(\Predis\Transaction\MultiExec $redis) use($goods_num){
// Atomic manipulation 、 Either they all succeed , Or it didn't work
$redis->decr('goods_num')->lpush('goods_num_list_1',$goods_num);
});
// Whether the transaction was successfully executed
if($result)
{
$userORM = $userService->get('1');
$userORM->increment('versionId',1);
}
return 'success';
}else{
return 'error: Inventory has been exhausted ';
}
}
1、 First, we need to listen that the value of the inventory field cannot change during the operation of our program , Otherwise, dirty data will be generated .
2、 We should write a queue mechanism , After the second kill , Will save as redis Add and create the order data of users who have succeeded in seckilling in .
边栏推荐
- Download and installation of universal player potplayer, live stream m3u8 import
- arrayList && linkedList
- Minimum spanning tree (prim+kruskal) learning notes (template +oj topic)
- 自定义View
- Echart折线图:当多条折线图的name一样时也显示不同的颜色
- Pod libwebp error reporting solution
- Not in the following list of legal domain names, wechat applet solution
- Wechat applet jumps to H5 page with parameters
- @The detailed explanation of configurationproperties and the problem that all properties of the entity bean modified by this annotation are null after injection are solved
- Local file search tool everything
猜你喜欢

【DP之01背包】

You still can't remotely debug idea? Come and have a look at my article. It's easy to use

Function and application scenario of field setaccessible() method

Pod libwebp error reporting solution

Self summarizing

Echart rectangular tree diagram: simple implementation of rectangular tree diagram

Rk3399 hid gadget configuration

USB 0xc0000011 error

Echart折线图:当多条折线图的name一样时也显示不同的颜色
![[spark]spark introductory practical series_ 8_ Spark_ Mllib (lower)__ Machine learning library sparkmllib practice](/img/65/a214d137e230b1a1190feb03660f2c.jpg)
[spark]spark introductory practical series_ 8_ Spark_ Mllib (lower)__ Machine learning library sparkmllib practice
随机推荐
What happens when the MySQL union index ABC encounters a "comparison operator"?
安全基线检查脚本—— 筑梦之路
Leetcode- hex number - simple
Leetcode- reverse string ii- simple
Leetcode- distribute cookies - simple
超有范的 logo 在线设计制作工具
Leetcode- first unique character in string - simple
Custom view
You still can't remotely debug idea? Come and have a look at my article. It's easy to use
Swift property property
Leetcode- keyboard line - simple
MySQL custom function
Leetcode- minimum number of operations to make array elements equal - simple
Concurrent programming -- countdownlatch combined with thread pool
Ffmpeg download suffix is Video files for m3u8
Leetcode longest harmonic subsequence simple
Power simple of leetcode-3
Concurrent programming -- what is threading?
View绘制整体流程简析
Wechat applet jumps to H5 page with parameters