feat(redis): Update Redis configuration and enhance compatibility with Docker
- Changed Redis port mapping in `docker-compose.yml` from `6379:6379` to `6380:6379` to avoid conflicts with Windows Redis. - Updated `.env.example` to reflect the new Redis URL (`redis://127.0.0.1:6380/0`), ensuring proper configuration for Docker users. - Enhanced Redis client initialization in `database.py` and `redis_gateway.py` to utilize a new `_redis_kwargs` function for improved compatibility with Windows Redis 3.x and Docker Redis 7. - Added a new PowerShell script `start-redis.ps1` to facilitate starting Redis in Docker, providing a seamless setup experience for developers. This update significantly improves the Redis integration, ensuring a smoother development process and better compatibility across environments.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user