Home >Backend Development >PHP Tutorial >About the use of reids in flash sales

About the use of reids in flash sales

WBOY
WBOYOriginal
2016-07-29 09:06:521036browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn