This commit is contained in:
Alex-larget
2026-03-24 15:44:08 +08:00
parent 346e8ab057
commit 28ad08da84
62 changed files with 814 additions and 840 deletions

View File

@@ -18,13 +18,15 @@ func Init(url string) error {
if err != nil {
return err
}
client = redis.NewClient(opt)
tmp := redis.NewClient(opt)
ctx := context.Background()
if err := client.Ping(ctx).Err(); err != nil {
client = nil // 连接失败时清空避免后续使用超时cache 将自动降级到内存备用
if err := tmp.Ping(ctx).Err(); err != nil {
_ = tmp.Close() // 避免未关闭客户端在后台持续 dial刷屏 pool 重试日志
client = nil
log.Printf("redis: 连接失败,已降级到内存缓存(%v", err)
return err
}
client = tmp
log.Printf("redis: connected to %s", opt.Addr)
return nil
}