feat(auth): cache sessions in redis with postgres fallback

This commit is contained in:
kk10
2026-10-06 15:36:52 +03:00
parent f7e1866d4e
commit 5bd210b59d
7 changed files with 126 additions and 15 deletions
+15 -1
View File
@@ -14,6 +14,7 @@ import (
"mtusi2026-messenger/internal/db"
"mtusi2026-messenger/internal/logger"
"mtusi2026-messenger/internal/postgres"
"mtusi2026-messenger/internal/redis"
"mtusi2026-messenger/internal/service"
)
@@ -41,6 +42,19 @@ func Run() error {
queries := db.New(pool)
cacheURL, err := cfg.Redis.URL()
if err != nil {
log.Error("read redis url", "error", err)
return err
}
rdb, err := redis.New(context.Background(), log, cacheURL)
if err != nil {
log.Error("create redis client", "error", err)
return err
}
defer rdb.Close()
cleanupCtx, stopCleanup := context.WithCancel(context.Background())
cleanupDone := make(chan struct{})
go func() {
@@ -52,7 +66,7 @@ func Run() error {
<-cleanupDone
}()
authService := service.NewAuthService(queries, cfg.Server.SessionTTL)
authService := service.NewAuthService(queries, rdb, cfg.Server.SessionTTL, log)
userService := service.NewUserService(queries)
chatService := service.NewChatService(pool, queries)
messageService := service.NewMessageService(queries)