FissionCommand.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Console\Commands\Redis;
  3. use App\Http\logic\api\ExtensionLogic;
  4. use App\Jobs\Demo1;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\Redis;
  7. class FissionCommand extends Command
  8. {
  9. // 1005=>TP、2030=>Rummy、2050=>Rummy两人、2060=>TPJoker玩法、2061=>TPAK玩法、2070=>Rummy10Card、2090=>Rummy两人十张
  10. // 2010=>百人TP、 2012=>百人AB 暂时忽略
  11. protected $GameIDs = [1005, 2030, 2050, 2060, 2061, 2070, 2090];
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'fission';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = '裂变-游戏对局';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. $logic = new ExtensionLogic();
  41. // $redis = new \Redis();
  42. // $redis->connect('8.129.91.11', '16973');
  43. // $redis->auth('0949jfi959t*fbf0o');
  44. $redis = Redis::connection('test');
  45. echo 'Start' . "\n";
  46. // 出栈
  47. while (true) {
  48. $brPop = $redis->brPop('gameCount', 0);
  49. $ret = $brPop[1] ?? 0;
  50. if (!empty($ret)) {
  51. $ret = explode(',', $ret);
  52. if (in_array($ret[1], $this->GameIDs)) {
  53. $UserID = $ret[0];
  54. $logic->invitation($UserID, 2);
  55. sleep(2);
  56. }
  57. }
  58. }
  59. }
  60. public function handle1()
  61. {
  62. dispatch(new Demo1());
  63. }
  64. }