// Package redisutil provides a Redis client constructor.
package redisutil

import (
	"context"
	"fmt"

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

// New creates and pings a Redis client.
func New(addr, password string, db int) (*redis.Client, error) {
	rdb := redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: password,
		DB:       db,
	})
	if err := rdb.Ping(context.Background()).Err(); err != nil {
		return nil, fmt.Errorf("redisutil.New ping: %w", err)
	}
	return rdb, nil
}
