v1.0.0

Architecture

Last updated


This page shows how the components of go-redis-fallback relate in one overview diagram.

System Overview


graph TB
    Client[Caller] --> API[Get / Set / Del]
    API --> Health{isHealth}
    Health -->|Normal| Mem[Memory Cache sync.Map]
    Health -->|Normal| Redis[(Redis)]
    Health -->|Fallback| Mem
    Mem -->|Fallback miss| File[Local JSON Files]
    API -->|Fallback write| Writer[Batch File Writer]
    Writer --> File
    Redis -->|Retries exhausted| Checker[Health-Check Ticker]
    Checker -->|Ping OK| Recovery[Recovery Flow]
    Recovery --> File
    Recovery --> Redis
    Sweeper[30s Expiry Sweep] --> Mem
    Sweeper --> File
  1. graph TB
  2. Client[Caller] --> API[Get / Set / Del]
  3. API --> Health{isHealth}
  4. Health -->|Normal| Mem[Memory Cache sync.Map]
  5. Health -->|Normal| Redis[(Redis)]
  6. Health -->|Fallback| Mem
  7. Mem -->|Fallback miss| File[Local JSON Files]
  8. API -->|Fallback write| Writer[Batch File Writer]
  9. Writer --> File
  10. Redis -->|Retries exhausted| Checker[Health-Check Ticker]
  11. Checker -->|Ping OK| Recovery[Recovery Flow]
  12. Recovery --> File
  13. Recovery --> Redis
  14. Sweeper[30s Expiry Sweep] --> Mem
  15. Sweeper --> File

Layers


LayerSourceResponsibility
Public APIget.go, set.go, del.go, instance.goRead the health flag and dispatch to Redis or the local path
Read pathget.goMemory first, Redis retries, degradation, restore from files
Mode switch and recoverysync.goHealth-check ticker, recovery resync, local file cleanup, read-repair
Batch file writerwriter.goQueue, merge by key, timed parallel flush
File layout and expiryunit.goThree-level MD5-sharded paths, TTL checks

Cross-Cutting Principles


PrincipleWhere
The memory cache is the first stop on every path; both modes check it firstget.go:25, get.go:64
The mode switch happens inside the failing call, so callers need no retryget.go:55-58, set.go:50-55
Local files are only scratch storage during fallback and are always deleted after recoverysync.go:84-87
TTL is stored as "write time + seconds" and recomputed on every tier's readunit.go:26-31

Further Reading


Per-module diagrams (read path, recovery, write path), the full sequence diagram, and the state machine are in the repo's doc/architecture.md.
中文