当前位置:网站首页>php redis 制作高迸发秒杀
php redis 制作高迸发秒杀
2022-06-13 05:58:00 【倾听岁月】
为什么说redis能支持高迸发呢?
具体实现
public function index13(UserService $userService)
{
//监听goods_num 即商品库存,如果在更新时,商品库存发生了变动(被其它进程修改),则不会更新成功
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){
//原子操作、要么都成功,要么都不成功
$redis->decr('goods_num')->lpush('goods_num_list_1',$goods_num);
});
//事务是否执行成功
if($result)
{
$userORM = $userService->get('1');
$userORM->increment('versionId',1);
}
return 'success';
}else{
return 'error:库存已完';
}
}
1、首先我们要监听库存字段的取值在我们程序操作期间是不能发生变化的,不然会产生脏数据。
2、我们应该写一个队列机制,在秒杀结束后,将存如redis中秒杀成功的用户的订单数据进行补充创建。
边栏推荐
- [spark]spark introductory practical series_ 8_ Spark_ Mllib (upper)__ Introduction to machine learning and sparkmllib
- MySQL fuzzy query and sorting by matching degree
- MySQL performs an inner join on query. The query result is incorrect because the associated fields have different field types.
- You still can't remotely debug idea? Come and have a look at my article. It's easy to use
- Leetcode- number of words in string - simple
- What happens when the MySQL union index ABC encounters a "comparison operator"?
- Hump naming and underlining
- Fusionpbx installation - road to dream
- High availability of Nacos series
- Leetcode- student attendance record i- simple
猜你喜欢

Timeout thread log for tongweb

2021.9.30学习日志-postman

中断处理过程

NVIDIA Jetson nano/xavier NX capacity expansion tutorial

2 first experience of drools

OpenGL mosaic (VIII)

MySQL performs an inner join on query. The query result is incorrect because the associated fields have different field types.

零拷贝技术

Mongodb multi field aggregation group by

Explanation of sentinel series' features, composition and deployment
随机推荐
Unity game optimization (version 2) learning record 7
安全基线检查脚本—— 筑梦之路
移动端适配方案
Hump naming and underlining
Power simple of leetcode-3
= = relation between int and integer
Leetcode judge subsequence simple
What happens when the MySQL union index ABC encounters a "comparison operator"?
Explanation of service registration and discovery API of Nacos series
Find out the missing numbers from the natural numbers arranged in order from 0 to 100, and the solution provides
Leetcode- distribute cookies - simple
Tongweb adapts to openrasp
SPI primary key generation strategy for shardingsphere JDBC
Implementation of concurrent programming locking
Interrupt processing
Initial redis experience
20 flowable container (event sub process, things, sub process, pool and pool)
Leetcode- keyboard line - simple
1 Introduction to drools rule engine (usage scenarios and advantages)
Annotation only integration SSM framework