47
CherryDB is a lightweight, educational implementation of a Redis-compatible key-value store written in Go. It is designed to demonstrate the internal workings of database systems, specifically focusing on the Redis Serialization Protocol (RESP) and persistent storage strategies.
Architecture: Operates as a TCP server on port :6379, utilizing lightweight Goroutines for per-client concurrency and sync.RWMutex for thread-safe data access.
RESP Compatibility: Fully implements the Redis Serialization Protocol with a custom parser and writer, allowing it to communicate with standard Redis clients.
Persistence (AOF): Ensures data durability via an Append Only File strategy. It logs every write operation (SET) and enforces a disk sync (fsync) every second, enabling crash recovery by replaying the log on startup.
Performance: Optimizes throughput by distinguishing between Read locks (for GET) and Write locks (for SET) and uses buffered I/O for efficient network transmission.
CherryDB supports a fundamental subset of Redis commands:
Data: SET (store key-value), GET (retrieve value).
System: PING (health check), QUIT (disconnect), HELLO (handshake/versioning).
As an educational tool, CherryDB has specific constraints compared to production Redis:
Data Types: Restricted to a simple string-to-string store; it lacks support for complex types like Lists, Hashes, Sets, or Sorted Sets.
Durability Window: The 1-second fsync interval means up to one second of data could potentially be lost in the event of a hard crash.
Scalability: While concurrent, the global mutex approach may become a bottleneck under extremely high write loads compared to Redis's single-threaded event loop or shard-based approaches.
Built with