Files
template-vitrine/backend/internal/platform/redis/redis.go
T
2026-09-14 20:50:19 +02:00

29 lines
579 B
Go

// Package redis provides the Redis client used for refresh-token/session state.
package redis
import (
"context"
"fmt"
"time"
"github.com/redis/go-redis/v9"
)
func Connect(redisURL string) (*redis.Client, error) {
opt, err := redis.ParseURL(redisURL)
if err != nil {
return nil, fmt.Errorf("parse redis url: %w", err)
}
client := redis.NewClient(opt)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := client.Ping(ctx).Err(); err != nil {
return nil, fmt.Errorf("ping redis: %w", err)
}
return client, nil
}