import lab3 files

This commit is contained in:
Голиков Maximillian Антон
2026-10-18 21:14:01 +03:00
parent ec540a1a72
commit 76322040e5
64 changed files with 4446 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
}