package redisv2

import (
	"fmt"

	"github.com/fiskerinc/cloud-services/pkg/utils/envtool"
	"github.com/redis/go-redis/v9"
)

// connection vars
var ()

// Actual connection to the redis
func NewConnection() (redisClient *redis.Client) {
	host := envtool.GetEnv("REDIS_HOST", "localhost")
	port := envtool.GetEnv("REDIS_PORT", "6379")
	username := envtool.GetEnv("REDIS_USERNAME", "default")
	password := envtool.GetEnv("REDIS_PASSWORD", "REPLACE_ME")
	addr := fmt.Sprintf("%v:%v", host, port)
	rdb := redis.NewClient(&redis.Options{
		Addr:           addr,
		Username:       username,
		Password:       password,
		MaxActiveConns: envtool.GetEnvInt("REDIS_MAXACTIVECONN", 10),
		PoolSize:       envtool.GetEnvInt("REDIS_POOLSIZE", 10),
	})

	return rdb
}
