2020-11-08 17:10:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Command;
|
|
|
|
|
|
|
|
use Hyperf\Command\Annotation\Command;
|
2020-12-02 15:14:29 +08:00
|
|
|
use Hyperf\Command\Command as HyperfCommand;
|
2020-11-08 17:10:05 +08:00
|
|
|
use Psr\Container\ContainerInterface;
|
2020-11-29 14:44:11 +08:00
|
|
|
use App\Service\SocketClientService;
|
2020-11-08 17:10:05 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Command
|
|
|
|
*/
|
|
|
|
class RemoveWsCacheCommand extends HyperfCommand
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var ContainerInterface
|
|
|
|
*/
|
|
|
|
protected $container;
|
|
|
|
|
|
|
|
public function __construct(ContainerInterface $container)
|
|
|
|
{
|
|
|
|
$this->container = $container;
|
|
|
|
|
|
|
|
parent::__construct('ws:remove-cache');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function configure()
|
|
|
|
{
|
|
|
|
parent::configure();
|
|
|
|
$this->setDescription('清除 WebSocket 客户端 FD 与用户绑定的缓存信息');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
2020-11-29 14:44:11 +08:00
|
|
|
$socket = new SocketClientService();
|
|
|
|
$this->line('此过程可能耗时较长,请耐心等待!', 'info');
|
2020-12-01 17:47:25 +08:00
|
|
|
|
|
|
|
// 获取所有已停止运行的服务ID
|
2020-11-29 14:44:11 +08:00
|
|
|
$arr = $socket->getServerRunIdAll(2);
|
2020-12-01 17:47:25 +08:00
|
|
|
|
2020-11-29 14:44:11 +08:00
|
|
|
foreach ($arr as $run_id => $value) {
|
|
|
|
go(function () use ($socket, $run_id) {
|
|
|
|
$socket->removeRedisCache($run_id);
|
|
|
|
});
|
2020-11-08 17:10:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->line('缓存已清除!', 'info');
|
|
|
|
}
|
|
|
|
}
|