偽代碼:
<?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; } } ?>
以上就介紹了關於秒殺搶購中reids的使用,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。