forked from mtusi2026/mtusi2026lab2
feat(auth): cache sessions in redis with postgres fallback
This commit is contained in:
+15
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user