DelPostNewComment.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Console\Commands\Tem;
  3. use App\Models\Post;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\Redis;
  6. class DelPostNewComment extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'post:del_post_new_comment';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '删除内容最火评论缓存';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct(Post $post)
  26. {
  27. parent::__construct();
  28. $this->post = $post;
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. $this->line("开始删除内容最火评论缓存");
  38. $count = $this->post->withTrashed()->count();
  39. $bar = $this->output->createProgressBar($count);
  40. $this->post->withTrashed()->chunk(100, function ($posts) use ($bar){
  41. foreach($posts as $post){
  42. Redis::DEL('post_new_comment_'.$post->id);
  43. $bar->advance();
  44. }
  45. usleep(50000);
  46. });
  47. $bar->finish();
  48. $this->line("\n删除内容最火评论缓存结束");
  49. }
  50. }