package service

import (
	"fmt"
	"sws_xcx/utils"

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

func RedisClient() *redis.Client {
	address := fmt.Sprintf("%s:%s", beego.AppConfig.String("redishost"), beego.AppConfig.String("redisport"))
	client := redis.NewClient(&redis.Options{
		Addr:     address,
		Password: beego.AppConfig.String("redispasswrod"),  // no password set
		DB:       beego.AppConfig.DefaultInt("redisdb", 4), // use default DB
	})
	pong, err := client.Ping().Result()
	if err != nil {
		utils.ErrorLog("redis connect error: %v", err)
	} else {
		utils.SuccessLog("redis connect success: %v", pong)
	}
	return client
}
