chore: lab import lab4 backend and infrastructure as baseline

This commit is contained in:
Голиков Maximillian Антон
2026-11-06 20:21:23 +03:00
parent 276dbdad8a
commit 4bba40d098
68 changed files with 5315 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
package redis
import (
"context"
"fmt"
"time"
"github.com/redis/go-redis/v9"
)
func NewClient(url string) (*redis.Client, error) {
opt, err := redis.ParseURL(url)
if err != nil {
return nil, fmt.Errorf("разбор URL: %w", err)
}
opt.DialTimeout = 700 * time.Millisecond
opt.ReadTimeout = 700 * time.Millisecond
opt.WriteTimeout = 700 * time.Millisecond
opt.MaxRetries = 1
opt.PoolSize = 10
opt.ConnMaxIdleTime = time.Minute
client := redis.NewClient(opt)
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
if err := client.Ping(ctx).Err(); err != nil {
_ = client.Close()
return nil, fmt.Errorf("ping: %w", err)
}
return client, nil
}