45 lines
1.4 KiB
PowerShell
45 lines
1.4 KiB
PowerShell
#Requires -Version 5.1
|
||||
|
|
<#
|
|||
|
|
.SYNOPSIS
|
|||
|
|
启动本机 Redis(Docker 优先,与 docker-compose.yml 一致)。
|
|||
|
|
.EXAMPLE
|
|||
|
|
.\scripts\dev\start-redis.ps1
|
|||
|
|
.NOTES
|
|||
|
|
连接串:.env REDIS_URL=redis://127.0.0.1:6380/0(Docker 映射,避开本机 Windows Redis 占 6379)
|
|||
|
|
#>
|
|||
|
|
$ErrorActionPreference = "Stop"
|
|||
|
|
$Root = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
|
|||
|
|
Set-Location $Root
|
|||
|
|
|
|||
|
|
function Test-DockerRedis {
|
|||
|
|
try {
|
|||
|
|
$p = docker exec jinrong-redis redis-cli ping 2>$null
|
|||
|
|
return $p -match "PONG"
|
|||
|
|
} catch {
|
|||
|
|
return $false
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
|
|||
|
|
Write-Host "未找到 docker 命令,请先启动 Docker Desktop。" -ForegroundColor Red
|
|||
|
|
exit 1
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$winRedis = Get-Service -Name "Redis" -ErrorAction SilentlyContinue
|
|||
|
|
if ($winRedis -and $winRedis.Status -eq "Running") {
|
|||
|
|
Write-Host "提示:本机 Windows Redis 仍占 6379;项目已改用 Docker 6380 → 见 .env REDIS_URL" -ForegroundColor DarkYellow
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Write-Host "启动 Docker Redis (jinrong-redis @ 127.0.0.1:6380)..." -ForegroundColor Cyan
|
|||
|
|
docker compose up -d redis
|
|||
|
|
Start-Sleep -Seconds 2
|
|||
|
|
|
|||
|
|
if (Test-DockerRedis) {
|
|||
|
|
docker compose ps redis
|
|||
|
|
Write-Host "Docker Redis 就绪 (redis:7-alpine @ 127.0.0.1:6380)" -ForegroundColor Green
|
|||
|
|
exit 0
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Write-Host "Docker Redis 未响应。请检查 Docker Desktop 是否运行:docker compose logs redis" -ForegroundColor Red
|
|||
|
|
exit 1
|