```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(cool): 添加Redis发布功能并实现巅峰赛匹配加入逻辑

新增RedisDo函数用于向Redis频道发布消息,并在巅峰赛场匹配
中添加玩家加入队列的功能。同时修复了socket连接关闭时资源
泄露问题,确保MsgChan正确关闭。

BREAKING CHANGE: 新增的RedisDo函数会直接panic处理错误,
需要调用方注意
This commit is contained in:
昔念
2026-03-04 03:22:43 +08:00
parent 10af34fdad
commit fb78147035
6 changed files with 210 additions and 0 deletions

View File

@@ -95,3 +95,17 @@ func Fail(message string) *BaseRes {
// }
// return nil, nil
// }
func RedisDo(ctx context.Context, funcstring string, a ...any) {
conn, err := g.Redis("cool").Conn(ctx)
if err != nil {
panic(err)
}
defer conn.Close(ctx)
_, err = conn.Do(ctx, "publish", funcstring, a)
if err != nil {
panic(err)
}
}

View File

@@ -136,6 +136,7 @@ func ListenFunc(ctx g.Ctx) {
continue
}
Logger.Info(ctx, "成功订阅 Redis 主题", "topic", subscribeTopic)
_, err = conn.Do(ctx, "subscribe", "sun:join:2458") //加入队列
// 4. 循环接收消息
connError := false