package clients

import (
	redis "github.com/redis/go-redis/v9"
	"log/slog"
	"os"
)

var Redis *redis.Client

func InitRedis() {
	host := os.Getenv("REDIS_HOST")
	if host == "" {
		slog.Debug("REDIS_HOST 环境变量未设置，使用默认值 localhost")
		host = "localhost"
	}
	port := os.Getenv("REDIS_PORT")
	if port == "" {
		slog.Debug("REDIS_PORT 环境变量未设置，使用默认值 6379")
		port = "6379"
	}
	password := os.Getenv("REDIS_PASSWORD")
	if password == "" {
		slog.Debug("REDIS_PASSWORD 环境变量未设置，使用默认值空字符串")
	}

	Redis = redis.NewClient(&redis.Options{
		Addr:     host + ":" + port,
		Password: password,
	})
}
