Browse Source

chore: test command

master
liyang 1 month ago
parent
commit
deb5d7dfc6
  1. 5
      app/command/ApiLogCommand.php
  2. 42
      app/command/TestCommand.php
  3. 1
      config/console.php

5
app/command/ApiLogCommand.php

@ -41,8 +41,9 @@ class ApiLogCommand extends Command
// 如果是 MySQL 2006 错误,则重连后再执行 // 如果是 MySQL 2006 错误,则重连后再执行
if (strpos($e->getMessage(), '2006 MySQL server has gone away') !== false) { if (strpos($e->getMessage(), '2006 MySQL server has gone away') !== false) {
Log::warning('MySQL connection lost, reconnecting...'); Log::warning('MySQL connection lost, reconnecting...');
Db::disconnect(); // 清理旧连接 Db::purge();
Db::reconnect(); // 重新连接 // Db::disconnect(); // 清理旧连接
// Db::reconnect(); // 重新连接
ApiLogModel::create($logData); // 重试一次 ApiLogModel::create($logData); // 重试一次
} else { } else {
throw $e; throw $e;

42
app/command/TestCommand.php

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace app\command;
use app\model\ApiLogModel;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Cache;
use think\facade\Log;
class TestCommand extends Command
{
protected function configure()
{
// 指令配置
$this->setName('test')
->setDescription('the test command');
}
/**
* Execute the console command.
*
* @param Input $input
* @param Output $output
* @return void
*/
protected function execute(Input $input, Output $output)
{
$cacheCode = Cache::store('redis')->keys('api_log');
dd($cacheCode);
$param['nation'] = '81';
$param['phone'] = '8057252138';
$mobile = $param['nation'] . ltrim($param['phone'], '0');
$smsKey = 'DB:USER:UNLOGIN:SMS_CODE:' . $mobile;
$cacheCode = Cache::store('redis')->get($smsKey);
dd($cacheCode);
}
}

1
config/console.php

@ -6,5 +6,6 @@ return [
// 指令定义 // 指令定义
'commands' => [ 'commands' => [
\app\command\ApiLogCommand::class, \app\command\ApiLogCommand::class,
\app\command\TestCommand::class,
], ],
]; ];

Loading…
Cancel
Save