JM-WechatMini/client/redis.go

26 lines
551 B
Go
Raw Permalink Normal View History

2023-11-02 04:34:46 +08:00
package client
import (
"context"
"git.echol.cn/loser/logger/log"
"github.com/go-redis/redis/v8"
"miniapp/global"
)
var Redis *redis.Client
func InitRedisClient() {
// 初始化连接
conn := redis.NewClient(&redis.Options{
Addr: global.GVA_CONFIG.Redis.Addr,
Password: global.GVA_CONFIG.Redis.Password,
DB: global.GVA_CONFIG.Redis.DB,
})
if err := conn.Ping(context.Background()).Err(); err != nil {
log.Panicf("Redis连接初始化失败: %v", err)
} else {
log.Debug("Redis连接初始化成功")
}
Redis = conn
}