12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Console\Commands\Tem;
- use App\Models\Post;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Redis;
- class DelPostNewComment extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'post:del_post_new_comment';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '删除内容最火评论缓存';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct(Post $post)
- {
- parent::__construct();
- $this->post = $post;
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $this->line("开始删除内容最火评论缓存");
- $count = $this->post->withTrashed()->count();
- $bar = $this->output->createProgressBar($count);
- $this->post->withTrashed()->chunk(100, function ($posts) use ($bar){
- foreach($posts as $post){
- Redis::DEL('post_new_comment_'.$post->id);
- $bar->advance();
- }
- usleep(50000);
- });
- $bar->finish();
- $this->line("\n删除内容最火评论缓存结束");
- }
- }
|