26 lines
551 B
Go
26 lines
551 B
Go
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
|
|
}
|