package cache

import (
	"fmt"
	"time"

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

func Open(rawURL string) (*redis.Client, error) {
	if rawURL == "" {
		return nil, nil
	}
	options, err := redis.ParseURL(rawURL)
	if err != nil {
		return nil, fmt.Errorf("parse redis URL: %w", err)
	}
	options.DialTimeout = 2 * time.Second
	options.ReadTimeout = time.Second
	options.WriteTimeout = time.Second
	options.PoolTimeout = 2 * time.Second
	return redis.NewClient(options), nil
}
