package proxyd

import (
	"context"
	"time"

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

func NewRedisClient(url string) (*redis.Client, error) {
	opts, err := redis.ParseURL(url)
	if err != nil {
		return nil, err
	}
	client := redis.NewClient(opts)
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	if err := client.Ping(ctx).Err(); err != nil {
		return nil, wrapErr(err, "error connecting to redis")
	}
	return client, nil
}
