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秒后再次请求 读取数据库更新状态的