fix redis clear

This commit is contained in:
2026-04-12 09:48:57 +08:00
parent 4463f73efb
commit a98d2b56ee
+10 -9
View File
@@ -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) {