go_gin_tmpl/client/redis.go

27 lines
529 B
Go
Raw Normal View History

2022-05-09 09:00:14 +08:00
package client
import (
"context"
"ginDemo/config"
"gitee.ltd/lxh/logger"
"github.com/go-redis/redis/v8"
)
var Redis *redis.Client
func InitRedisClient() {
conf := config.Scd.Redis
// 初始化连接
conn := redis.NewClient(&redis.Options{
Addr: conf.GetDSN(),
Password: conf.Password,
DB: conf.Db,
})
if err := conn.Ping(context.Background()).Err(); err != nil {
logger.Say.Panicf("Redis连接初始化失败: %v", err)
} else {
logger.Say.Debug("Redis连接初始化成功")
}
Redis = conn
}