You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
592 B
Go
29 lines
592 B
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
"github.com/denisovdennis/autohero/internal/config"
|
|
)
|
|
|
|
// NewRedis creates a Redis client and verifies the connection.
|
|
func NewRedis(ctx context.Context, cfg config.RedisConfig, logger *slog.Logger) (*redis.Client, error) {
|
|
client := redis.NewClient(&redis.Options{
|
|
Addr: cfg.Addr,
|
|
DB: 0,
|
|
PoolSize: 20,
|
|
})
|
|
|
|
if err := client.Ping(ctx).Err(); err != nil {
|
|
return nil, fmt.Errorf("ping redis: %w", err)
|
|
}
|
|
|
|
logger.Info("connected to Redis", "addr", cfg.Addr)
|
|
|
|
return client, nil
|
|
}
|