From a98d2b56ee5058dc735a032832a2ac848324d18a Mon Sep 17 00:00:00 2001 From: commie Date: Sun, 12 Apr 2026 09:48:57 +0800 Subject: [PATCH] fix redis clear --- app/command/Backup.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/command/Backup.php b/app/command/Backup.php index 494f7b8..4b6f73f 100644 --- a/app/command/Backup.php +++ b/app/command/Backup.php @@ -40,7 +40,7 @@ class Backup extends Command 'database' => 0, 'username' => '', 'password' => 'n1e5a6s6m7', - 'useDocker' => false, + 'useDocker' => true, 'dockerContainerName' => 'redis' // Docker 容器名称 ], [ @@ -681,8 +681,12 @@ class Backup extends Command } } - if ($redisSource && $redisSource['useDocker']) { - // 使用 Docker 容器 + if (!$redisSource) { + $output->writeln("❌ 未找到 Redis 数据源配置"); + return; + } + + if ($redisSource['useDocker']) { $redisContainer = $redisSource['dockerContainerName']; if (!$redisContainer) { $output->writeln("❌ 未指定 Redis Docker 容器名称"); @@ -701,12 +705,10 @@ class Backup extends Command $output->writeln(implode("\n", $outputLines)); } } else { - // 尝试使用 Redis 连接 $redis = new \Redis(); - $config = config('cache.stores.redis'); - $host = $config['host'] ?? '127.0.0.1'; - $port = $config['port'] ?? 6379; - $password = $config['password'] ?? ''; + $host = $redisSource['host'] ?? '127.0.0.1'; + $port = $redisSource['port'] ?? 6379; + $password = $redisSource['password'] ?? ''; $output->writeln("连接 Redis: {$host}:{$port}"); @@ -715,7 +717,6 @@ class Backup extends Command $redis->auth($password); } - // 清空 Redis $result = $redis->flushAll(); if ($result) {