feat: port lab4 implementation

This commit is contained in:
kk10
2026-11-13 15:52:39 +03:00
parent 276dbdad8a
commit 36d9b0c8f6
101 changed files with 8426 additions and 6 deletions
+32
View File
@@ -0,0 +1,32 @@
package redis
import (
"context"
"fmt"
"log/slog"
"time"
goredis "github.com/redis/go-redis/v9"
)
func New(ctx context.Context, log *slog.Logger, url string) (*goredis.Client, error) {
opts, err := goredis.ParseURL(url)
if err != nil {
return nil, fmt.Errorf("parse redis url: %w", err)
}
opts.DialTimeout = 1 * time.Second
opts.ReadTimeout = 200 * time.Millisecond
opts.WriteTimeout = 200 * time.Millisecond
opts.MaxRetries = -1
client := goredis.NewClient(opts)
pingCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
if err := client.Ping(pingCtx).Err(); err != nil {
log.Warn("redis unavailable, running without cache", "error", err)
}
return client, nil
}