ClearCampaignRedis.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2019/1/7
  6. * Time: 下午3:49
  7. */
  8. namespace app\admin\command;
  9. use app\common\library\Redis;
  10. use think\console\Command;
  11. use think\console\Input;
  12. use think\console\input\Argument;
  13. use think\console\Output;
  14. use think\Request;
  15. class ClearCampaignRedis extends Command
  16. {
  17. public function Configure()
  18. {
  19. $this->setName('ClearCampaignRedis')
  20. ->addArgument('pre', Argument::OPTIONAL, 'redis前缀', null)
  21. ->addArgument('key', Argument::OPTIONAL, '要清除得key', null)
  22. ->setDescription('clear ClearCampaignRedis redis');
  23. }
  24. /**
  25. * @param Input $input
  26. * @param Output $output
  27. * @return int|null|void
  28. * @throws \Exception
  29. * @throws \think\Exception
  30. */
  31. public function execute(Input $input, Output $output)
  32. {
  33. Request::instance()->module('admin');
  34. $pre = $input->getArgument('pre');
  35. $key = $input->getArgument('key');
  36. $redisArr = [
  37. 'MR:','MRLATEST','MC:','UCR:','UMCS:','UMO:','CMK:','UMF:','MCL:','LK:','MCS:','MC_USERLIST','SAB:','SAU:','SAUL:',
  38. ];
  39. if (!in_array($pre, $redisArr) || strstr($pre,'*') !== false || strstr($key,'*') !== false ){
  40. echo '不能清除此key';exit;
  41. }
  42. $res = Redis::instance()->del($key);
  43. dump($res);
  44. }
  45. }