We put a Redis server inside our runtime
3 days ago
- #Redis
- #Development Environment
- #Backend Development
- Encore enables running identical backend code across local development, testing, and production environments, with infrastructure declared directly in the code and provisioned per environment.
- For local development, Encore's runtime includes an in-memory Redis server built directly into the process, avoiding external dependencies like Docker containers or mocks that might behave differently.
- Originally implemented in Go using alicebob/miniredis for Go applications, Encore ported this to Rust to embed within the Rust runtime for TypeScript apps, totaling around 25,000 lines and supporting key Redis data types and protocols.
- The embedded server mimics real Redis behavior, including time-based expiry via a mock clock and key pruning to prevent unlimited growth, ensuring local development closely matches production behavior.
- Applications declare caches in code, and the runtime automatically uses the embedded server locally or connects to a managed Redis in production based on configuration flags, with no changes needed in application code.
- To ensure parity, the Rust server is tested against the original Go miniredis suite, comparing raw RESP responses byte-for-byte to catch subtle differences in command handling or TLS implementation.
- The in-memory server is intended only for development and testing; in production, Encore provisions scalable managed Redis instances, maintaining consistency without requiring manual infrastructure setup locally.