89 lines
2.9 KiB
PowerShell
89 lines
2.9 KiB
PowerShell
# Redis配置验证脚本
|
|
# 用于验证发布后的Redis配置是否正确
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "Redis配置验证脚本" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# 1. 检查配置文件是否存在
|
|
Write-Host "1. 检查配置文件..." -ForegroundColor Yellow
|
|
$files = @(
|
|
"appsettings.json",
|
|
"appsettings.Development.json",
|
|
"appsettings.Production.json"
|
|
)
|
|
|
|
foreach ($file in $files) {
|
|
if (Test-Path $file) {
|
|
Write-Host " ✓ $file 存在" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " ✗ $file 不存在" -ForegroundColor Red
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# 2. 读取并显示Redis配置
|
|
Write-Host "2. 读取Redis配置..." -ForegroundColor Yellow
|
|
|
|
function Show-RedisConfig {
|
|
param($configFile)
|
|
|
|
if (Test-Path $configFile) {
|
|
Write-Host " 配置文件: $configFile" -ForegroundColor Cyan
|
|
$config = Get-Content $configFile -Raw | ConvertFrom-Json
|
|
|
|
if ($config.RedisSetting) {
|
|
Write-Host " Host: $($config.RedisSetting.Host)" -ForegroundColor White
|
|
Write-Host " Port: $($config.RedisSetting.Port)" -ForegroundColor White
|
|
Write-Host " Auth: $(if($config.RedisSetting.Auth){'已配置'}else{'未配置'})" -ForegroundColor White
|
|
Write-Host " DefaultDatabaseIndex: $($config.RedisSetting.DefaultDatabaseIndex)" -ForegroundColor White
|
|
} else {
|
|
Write-Host " 未找到RedisSetting配置节" -ForegroundColor Red
|
|
}
|
|
Write-Host ""
|
|
}
|
|
}
|
|
|
|
Show-RedisConfig "appsettings.json"
|
|
Show-RedisConfig "appsettings.Production.json"
|
|
|
|
# 3. 测试Redis连接
|
|
Write-Host "3. 测试Redis连接..." -ForegroundColor Yellow
|
|
|
|
$config = Get-Content "appsettings.json" -Raw | ConvertFrom-Json
|
|
$host_addr = $config.RedisSetting.Host
|
|
$port = $config.RedisSetting.Port
|
|
|
|
Write-Host " 正在测试连接到 ${host_addr}:${port}..." -ForegroundColor White
|
|
|
|
try {
|
|
$tcpClient = New-Object System.Net.Sockets.TcpClient
|
|
$tcpClient.Connect($host_addr, $port)
|
|
|
|
if ($tcpClient.Connected) {
|
|
Write-Host " ✓ Redis服务器可访问" -ForegroundColor Green
|
|
$tcpClient.Close()
|
|
}
|
|
} catch {
|
|
Write-Host " ✗ 无法连接到Redis服务器: $_" -ForegroundColor Red
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# 4. 检查环境变量
|
|
Write-Host "4. 检查环境变量..." -ForegroundColor Yellow
|
|
$aspnetEnv = $env:ASPNETCORE_ENVIRONMENT
|
|
if ($aspnetEnv) {
|
|
Write-Host " ASPNETCORE_ENVIRONMENT = $aspnetEnv" -ForegroundColor White
|
|
} else {
|
|
Write-Host " ASPNETCORE_ENVIRONMENT 未设置 (默认为 Production)" -ForegroundColor Yellow
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "验证完成" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
|