Files
trex-core/docs/batches/bat-005_20260604_kis-token-redis-cache/index.md
T
genichinandClaude Opus 4.8 ac6061f510 Deliver BAT-005: KIS token Redis cache (REQ-016, minor-change)
Port the trex-orbit Redis token-cache pattern so the KIS access token
survives daemon restarts and is shared across processes, avoiding KIS
token-issuance rate limits. KISBroker._ensure_token now resolves L1
in-memory -> L2 cache -> issue, storing issued tokens back to the cache.

- adapters/broker/token_cache.py: TokenCache protocol + RedisTokenCache
  (key trex:broker:kis:{account_ref}:token, token+expiry+app_key suffix
  JSON, ex=ttl, best-effort with graceful fallback) + InMemoryTokenCache.
- kis.py: optional token_cache injection.
- runtime config/daemon: TREX_KIS_REDIS_URL wires a RedisTokenCache.
- pyproject: redis>=5.

Verification: 96 passed, ruff clean — cache hit avoids issuance, cache is
shared across instances (restart/multi-process survival), backend errors
fall back to issuance (no regression), and app_key-suffix mismatch
invalidates a stale cache. Tested deterministically with an in-memory
double (no Redis server required). Processed via the minor-change fast
path: REQ-016 -> Implemented, BAT-005 (batch-lite) -> release-candidate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 18:44:09 +09:00

1.5 KiB

BAT-005: KIS 토큰 Redis 캐시 (minor-change)

  • Status: release-candidate
  • Profile: batch-lite
  • Source Discovery: dcy-003 (REQ-012 운영 견고성 보완)
  • Included REQ: REQ-016
  • Excluded REQ: 없음

Summary

  • REQ-016 단일 저위험 Integration 요구사항을 minor-change 로 처리. KISBroker 에 선택적 Redis 토큰 캐시(L1 인메모리 → L2 Redis → 발급)를 더해 재기동/다중 프로세스 토큰 생존 + rate-limit 회피. orbit Redis 캐시 패턴 이식.

Scope

  • In Scope:
    • TokenCache 추상화 + RedisTokenCache(redis.from_url, 키 trex:broker:kis:{account_ref}:token, app_key suffix 안전, ex=ttl) + 테스트용 인메모리 더블.
    • KISBroker _ensure_token 3-레벨 + graceful fallback. config TREX_KIS_REDIS_URL + daemon wiring. pyproject redis 의존.
    • 캐시 히트/공유/폴백/suffix 단위테스트.
  • Out of Scope:
    • 다른 캐시 백엔드(PG/파일), 토큰 외 응답 캐시.

Documents

Notes

  • minor-change: 기존 BrokerPort 뒤 토큰 캐시 계층 추가, 외부 인터페이스·슬롯 흐름 불변. design 불요.
  • 실 Redis 없을 때도 graceful fallback → 단일 데몬 회귀 없음. 테스트는 인메모리 캐시 더블로 결정적 검증(실 Redis 서버 불요).