package init_serve

import (
	"context"
	"github.com/go-redis/redis/v8"
	"hongze/hongze_yb/global"
)

func Redis() {
	redisConf := global.CONFIG.Redis
	client := redis.NewClient(&redis.Options{
		Addr:     redisConf.Address,
		Password: redisConf.Password,
		DB:       redisConf.Db,
		//PoolSize: 10, //连接池最大socket连接数，默认为10倍CPU数， 10 * runtime.NumCPU（暂不配置）
	})
	_, err := client.Ping(context.TODO()).Result()
	if err != nil {
		global.LOG.Error("redis 链接失败:", err)
		panic("redis 链接失败:" + err.Error())
	}

	//全局赋值redis链接
	global.Redis = client
}
