Pseudocode:
<?php $watchKey = $redis->get("watchKey"); $total = 100; //数量 if($watchKey < $total){ $redis->watch("watchKey"); $redis->multi(); //插入数据 $redis->hSet("watchList","user_id_".$user_id_, $data); $redis->set("watchKey",$watchKey++); $result = $redis->exec(); if($result){ echo "抢购成功!<br/>"; if(function_exists("fastcgi_finish_request")){ fastcgi_finish_request(); processData($data); }else{ $watchList = $redis->hGetAll("watchList"); //Async Processing; } }else{ echo "手气不好"; die; } } ?>
The above introduces the use of reids in flash sales, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.