redis 限流
protected function queue() { //生成下一分钟的redis队列 $nextMinute = date("Y-m-d H:i", strtotime("+1 minute")); $time = strtotime($nextMinute); for ($i = 0; $i <= 60; $i++) { $redis_key = $time + $i; $redis_key = 'miniproduct:legtype:' . $redis_key; $redisListData = [0, 1, 2, 2, 3, 3, 0, 1, 2, 2, 3, 3, 0, 1, 2, 2, 3, 3, 0, 1, 2, 2, 3, 3, 0, 1, 2, 2, 3, 3]; shuffle($redisListData); Cache::store('redis')->handler()->lpush($redis_key, ...$redisListData); Cache::store('redis')->handler()->expire($redis_key, 120); } echo '执行成功'; }
//QPS限制判断 $redis_key = "miniproduct:legtype:" . time(); $index = Cache::store('redis')->handler()->lpop($redis_key); if (is_numeric($index)) { //相关业务 } else { return ResponseHelper::returnJson(-1, "当前请求人数过多,请稍后重试!", []); }
posted on 2022-03-31 10:33 running-fly 阅读(28) 评论(0) 编辑 收藏 举报