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

About the use of reids in flash sales

WBOY
Release: 2016-07-29 09:06:52
Original
1035 people have browsed it

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;
    }
}
?>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template