12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/7/2
- * Time: 14:49
- */
- namespace App\Console\Commands;
- use App\Models\PostData;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class PostCreateBean extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'post:create_bean';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '内容生成U米';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct(PostData $postData)
- {
- parent::__construct();
- $this->postData = $postData;
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $this->line("开始更新内容生成U米");
- $key = 'post_create_bean';
- $ids = Redis::ZRANGE($key, 0 , -1, 'WITHSCORES');
- foreach($ids as $postId => $val){
- try{
- $value = Redis::ZSCORE($key, $postId);
- Redis::ZREM ($key, $postId);
- $this->postData->where('post_id', $postId)->increment('create_bean', $value);
- Log::debug('更新内容生成U米成功'.$postId.'-'.$value);
- }catch (\Exception $exception){
- Log::error('更新内容生成U米失败'.$postId.'-'.$val.$exception->getMessage());
- }
- usleep(10000);
- }
- $this->line("更新内容生成U米结束");
- }
- }
|