feat: increased security
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2026-02-21 21:05:47 +03:00
parent 04830681b9
commit 8befcc11c1
14 changed files with 233 additions and 50 deletions

View File

@@ -2,32 +2,27 @@ package db
import (
"context"
"log"
"fmt"
"time"
"example.com/m/internal/config"
"github.com/redis/go-redis/v9"
)
var Redis *redis.Client
func InitRedis(cfg *config.Config) (*redis.Client, error) {
opt, err := redis.ParseURL(cfg.RedisURL)
if err != nil {
log.Fatalf("impossible to parse redis url: %v", err)
return nil, err
return nil, fmt.Errorf("failed to parse redis url: %w", err)
}
Redis = redis.NewClient(opt)
client := redis.NewClient(opt)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := Redis.Ping(ctx).Err(); err != nil {
log.Fatalf("impossible to conenct to redis db: %v", err)
return nil, err
if err := client.Ping(ctx).Err(); err != nil {
return nil, fmt.Errorf("failed to connect to redis: %w", err)
}
return Redis, nil
return client, nil
}