package initApp

import (
	"DataShare/global"
	"fmt"
	"github.com/go-redis/redis/v7"
	"github.com/sirupsen/logrus"
)

func RedisInit() error{

	global.RedisDataShare = "AnRedis"
	client := redis.NewClient(&redis.Options{
		Addr:     global.SystemConfig.Redis.Host,
		Password: global.SystemConfig.Redis.Password,
		DB:       global.SystemConfig.Redis.Db,
	})
	pong,err := client.Ping().Result()
	if err != nil {
		global.SystemLogger.Log(logrus.ErrorLevel,fmt.Sprintf("init redis failed, errmsg:%s",err.Error()))
		return err
	}

	global.SystemLogger.Log(logrus.ErrorLevel,fmt.Sprintf("redis connect ping response:%s",pong))
	global.RedisClient = client

	return nil
}