phpredis防止超卖的方法

phpredis防止超卖的方法

 

        $redis = \RedisClient::getInstance();
        if ($redis->get(self::TABLEPRE . '_red') >= 100) {
            echo '红包没有了';
            exit();
        } else {
            $yijingred = $redis->incr(self::TABLEPRE . '_red');
            if ($yijingred >= 100) {
                $redis->decr(self::TABLEPRE . '_red');
                echo '红包没有了';
                exit();
            }
        }

还有种方法就是消息队列

lpop读取。。。然后更新数据库表       客户度需要3秒后再次请求 读取数据库更新状态的

posted @ 2021-06-22 17:12  newmiracle宇宙  阅读(154)  评论(0编辑  收藏  举报