Files
CU_Points/backend/pkg/cache/redis.go
T
emilandClaude Sonnet 4.6 50b3c4198a feat: initial commit — backend API + student cabinet frontend
- Go backend: auth (JWT), points earn/spend, QR token generation,
  partners, admin grant/stats endpoints with chi router
- Next.js 14 frontend: login, student dashboard, transaction history,
  QR display, partners list
- PostgreSQL migrations (4 tables), Redis cache, Docker Compose
- CORS middleware, role-based route protection, Zustand auth store

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 10:03:27 +03:00

24 lines
654 B
Go

// Package cache provides Redis client initialization.
package cache
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
// NewClient creates and validates a Redis client using the given REDIS_URL.
// Returns an error if the URL cannot be parsed or if the initial PING fails.
func NewClient(ctx context.Context, redisURL string) (*redis.Client, error) {
opts, err := redis.ParseURL(redisURL)
if err != nil {
return nil, fmt.Errorf("cache.NewClient: parse URL: %w", err)
}
client := redis.NewClient(opts)
if err := client.Ping(ctx).Err(); err != nil {
return nil, fmt.Errorf("cache.NewClient: ping: %w", err)
}
return client, nil
}