12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- 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
- {
-
- protected $signature = 'post:create_bean';
-
- protected $description = '内容生成U米';
-
- public function __construct(PostData $postData)
- {
- parent::__construct();
- $this->postData = $postData;
- }
-
- 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米结束");
- }
- }
|