package redis

import (
	"boss/internal/config"
	"fmt"
	"github.com/go-redis/redis/v7"
	"time"
)

// New 创建redis客户端
func New() *redis.Client {
	if Client != nil {
		return Client
	}
	redisCfg, err := config.GetRedisConfig()
	if err != nil {

	}

	Client = redis.NewClient(&redis.Options{
		Addr:     fmt.Sprintf("%s:%s", redisCfg.Host, redisCfg.Host), // redis地址
		Password: redisCfg.Password,                                  // 密码
		DB:       redisCfg.DB,                                        // 使用默认数据库
	})
	return Client
}

var Client *redis.Client

func init() {
	New()
}

// Set 设置key-value
func Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd {
	return Client.Set(key, value, expiration)
}
