реализован уровень 4

This commit is contained in:
2026-10-15 20:12:22 +03:00
parent 158fed100c
commit 09b4b1d49d
25 changed files with 1794 additions and 91 deletions
+38 -1
View File
@@ -10,6 +10,7 @@ import (
"syscall"
"time"
applicationCache "mtusi2026lab2/internal/cache"
"mtusi2026lab2/internal/config"
"mtusi2026lab2/internal/database"
"mtusi2026lab2/internal/store"
@@ -41,8 +42,44 @@ func main() {
cfg.DatabaseQueryTimeout,
)
var applicationStore store.Repository = postgresStore
if cfg.RedisURL != "" {
redisChatCache, cacheError := applicationCache.NewRedisChatCache(
cfg.RedisURL,
cfg.RedisCacheTTL,
cfg.RedisOperationTimeout,
cfg.RedisPoolSize,
)
if cacheError != nil {
log.Fatalf("[FATAL] Invalid Redis configuration: %v", cacheError)
}
defer func() {
if closeError := redisChatCache.Close(); closeError != nil {
log.Printf("[WARN] Redis client close failed: %v", closeError)
}
}()
cacheContext, cacheCancel := context.WithTimeout(
context.Background(),
cfg.RedisOperationTimeout,
)
if cacheError = redisChatCache.Ping(cacheContext); cacheError != nil {
log.Printf("[WARN] Redis unavailable at startup; PostgreSQL fallback is active: %v", cacheError)
} else {
log.Println("[INFO] Redis chat cache is available")
}
cacheCancel()
applicationStore = store.NewCachedRepository(
postgresStore,
redisChatCache,
log.Default(),
)
}
handler := handlers.NewHandler(
postgresStore,
applicationStore,
handlers.WithReadiness(
databasePool,
cfg.ReadinessTimeout,