28 lines
532 B
Go
28 lines
532 B
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/cloudwego/hertz/pkg/common/hlog"
|
|
"github.com/go-redis/redis/v8"
|
|
"userAuthCenter/config"
|
|
)
|
|
|
|
var Rdb *redis.Client
|
|
var ctx = context.Background()
|
|
|
|
// 初始化Redis连接
|
|
func InitRedis() {
|
|
Rdb = redis.NewClient(&redis.Options{
|
|
Addr: fmt.Sprintf("%s:%s", config.RedisHost, config.RedisPort),
|
|
Password: "",
|
|
DB: 0,
|
|
})
|
|
|
|
if _, err := Rdb.Ping(ctx).Result(); err != nil {
|
|
hlog.Errorf("无法连接Redis: %v", err)
|
|
panic(err)
|
|
}
|
|
hlog.Info("已连接Redis")
|
|
}
|