package rediscli

import (
	"fmt"

	"mtp2_if/config"

	"github.com/go-redis/redis"
)

var RedisCli *redis.Client

func InitRedisCli() error {
	RedisCli = redis.NewClient(&redis.Options{
		Addr:     config.SerCfg.GetRedisAddress(),
		Password: config.SerCfg.GetRedisPwd(),
		DB:       config.SerCfg.GetRedisDbNum(),
		PoolSize: config.SerCfg.GetRedisConnNum(),
	})

	pong, err := RedisCli.Ping().Result()
	if err != nil {
		fmt.Println(pong, err)
		return err
	}

	return nil
}

func GetRedisClient() *redis.Client {
	return RedisCli
}

func CloseReidsClient() {
	RedisCli.Close()
}
