first commit

This commit is contained in:
2026-02-06 21:08:15 +03:00
commit 2d7bd20ac0
12 changed files with 395 additions and 0 deletions

33
internal/db/redis.go Normal file
View File

@@ -0,0 +1,33 @@
package db
import (
"context"
"log"
"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
}
Redis = 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
}
return Redis, nil
}