feat(server): WebSocket 广播支持 Redis Pub/Sub 跨节点扇出(REDIS_ADDR 可选开关)
- 新增 ws.EventBus 接口与 RedisBus 实现;Hub 五类广播改为发布信封、各节点订阅后本地投递 - 单实例不设 REDIS_ADDR 保持进程内直投;Redis 不可用时自动兜底本地投递 - config 新增 REDIS_ADDR/REDIS_PASSWORD/REDIS_DB;dev compose 增加 --profile redis (6380) - prod compose 与 .env.prod.example 增加多副本配置说明;README 更新已知边界 - 已用双实例 + 真实 Redis 实测跨节点推送;新增总线单测(含发布失败兜底),-race 通过
This commit is contained in:
@@ -12,6 +12,7 @@ type Config struct {
|
||||
Database DatabaseConfig
|
||||
JWT JWTConfig
|
||||
Storage StorageConfig
|
||||
Redis RedisConfig
|
||||
AllowedOrigins []string
|
||||
}
|
||||
|
||||
@@ -48,6 +49,13 @@ type StorageConfig struct {
|
||||
WebPQuality float32
|
||||
}
|
||||
|
||||
// RedisConfig 可选的跨节点 WebSocket 广播总线(多 API 副本部署时启用)。
|
||||
type RedisConfig struct {
|
||||
Addr string // 为空表示单实例模式,WS 广播仅进程内
|
||||
Password string
|
||||
DB int
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
return &Config{
|
||||
Server: ServerConfig{
|
||||
@@ -80,6 +88,11 @@ func Load() *Config {
|
||||
WebPQuality: float32(getEnvInt("STORAGE_WEBP_QUALITY", 80)),
|
||||
},
|
||||
AllowedOrigins: splitCSV(getEnv("CORS_ALLOW_ORIGINS", "*")),
|
||||
Redis: RedisConfig{
|
||||
Addr: getEnv("REDIS_ADDR", ""),
|
||||
Password: getEnv("REDIS_PASSWORD", ""),
|
||||
DB: getEnvInt("REDIS_DB", 0),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user