mirror of
https://gitee.com/shikong-sk/gofiber-study
synced 2025-02-23 23:32:15 +08:00
34 lines
636 B
Go
34 lines
636 B
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"github.com/go-redis/redis/v8"
|
|
"gofiber.study.skcks.cn/common/config"
|
|
"gofiber.study.skcks.cn/common/logger"
|
|
"gofiber.study.skcks.cn/global"
|
|
)
|
|
|
|
func reloadRedis(c *config.BasicConfig) {
|
|
if global.Redis != nil {
|
|
_ = global.Redis.Close()
|
|
}
|
|
|
|
r := redis.NewClient(&redis.Options{
|
|
Addr: c.Redis.Addr,
|
|
Password: c.Redis.Pass,
|
|
DB: c.Redis.DB,
|
|
})
|
|
|
|
ctx := context.Background()
|
|
_, err := r.Ping(ctx).Result()
|
|
if err != nil {
|
|
logger.Log.Fatalln("[x] [Redis] 连接失败: %s", err)
|
|
}
|
|
|
|
mainAppExec(func() {
|
|
logger.Log.Infoln("[√] [Redis] 连接成功")
|
|
})
|
|
|
|
global.Redis = r
|
|
}
|