feat: DB DI 전환 + download 하위 호환성 + race condition 수정
- middleware(Auth, Idempotency)를 클로저 팩토리 패턴으로 DI 전환 - database.DB/RDB 전역 변수 제거, ConnectMySQL/Redis 값 반환으로 변경 - download API X-API-Version 헤더 + 하위 호환성 규칙 문서화 - SaveGameData PlayTimeDelta 원자적 UPDATE (race condition 해소) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,14 +7,13 @@ import (
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// TODO: Consider injecting RDB as a dependency instead of using a package-level global
|
||||
// to improve testability. Currently, middleware directly accesses this global.
|
||||
var RDB *redis.Client
|
||||
|
||||
func ConnectRedis() error {
|
||||
RDB = redis.NewClient(&redis.Options{
|
||||
func ConnectRedis() (*redis.Client, error) {
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: config.C.RedisAddr,
|
||||
Password: config.C.RedisPassword,
|
||||
})
|
||||
return RDB.Ping(context.Background()).Err()
|
||||
if err := rdb.Ping(context.Background()).Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rdb, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user