12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Topic;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class TopicUseCount extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'post:topic_use_count';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '添加话题使用数';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct(Topic $topic)
- {
- parent::__construct();
- $this->topic = $topic;
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $this->line("开始添加话题使用数");
- $key = 'topic.just_use_count';
- $ids = Redis::ZRANGE($key, 0 , -1, 'WITHSCORES');
- foreach($ids as $topicId => $val){
- try{
- $value = Redis::ZSCORE($key, $topicId);
- Redis::ZREM ($key, $topicId);
- $this->topic->where('id', $topicId)->increment('use_count', $value);
- Log::debug('添加话题使用数成功'.$topicId.'-'.$value);
- }catch (\Exception $exception){
- Log::error('添加话题使用数失败'.$topicId.'-'.$val.$exception->getMessage());
- }
- usleep(10000);
- }
- $this->line("更新内容生成U米结束");
- }
- }
|