This project is a high-performance, concurrent, in-memory data structure store built from scratch in Go, designed to emulate the behavior and protocol of a traditional Redis server. It acts as a drop-in replacement capable of communicating with standard Redis clients (like redis-cli) while implementing complex internal engine mechanics like data persistence, memory eviction schemes, and transaction queues.
Here is a breakdown of the major technical features and architectural decisions implemented in this application:
The server communicates natively using the official RESP protocol. It includes a custom parser and deserializer built around buffered I/O that flawlessly encodes and decodes:
While standard Redis is fundamentally single-threaded, this clone leverages Go's concurrency model (Goroutines) to handle multiple client connections simultaneously.
RWMutex, allowing simultaneous non-blocking concurrent reads while securely locking the dataset during write operations.To prevent data loss on server restarts, the application implements both of Redis's primary, complex persistence strategies:
gob encoding. It tracks key mutations and triggers automatic background saves based on configurable thresholds (e.g., save after 1000 changes in 60 seconds). To ensure data integrity, RDB snapshot files track and verify SHA256 checksums asynchronously.always, everysec, no). It also supports Background AOF Rewriting (BGREWRITEAOF)โwhich compacts the event log into its shortest possible sequence of commands without halting the main server's operations.Ensuring the server doesn't crash on high workloads, the internal database enforces maximum memory constraints coupled with intelligent eviction algorithms:
maxmemory limit is hit.allkeys-random, allkeys-lru, and allkeys-lfu policies.Provides full support for standard Redis transactions allowing groups of commands to be queued and executed atomically.
MULTI, EXEC, and DISCARD.EXEC is invoked.Supports temporal data capabilities, allowing clients to assign expiry times to specific keys.
EXPIRE and TTL.MONITORImplements advanced introspection by allowing developer clients to hook into the MONITOR command. The server safely broadcasts every executed command from any client to all active monitor hooks in real-time, aiding debugging and traffic auditing.
INFO)Exposes an INFO gateway that dynamically builds real-time server statistics. Retrieves operating system level metrics using gopsutil to show exact total system memory, peak memory consumption, persistence tracking stats, and network connection statistics.
Provides a custom initialization engine that parses an external redis.conf format file. It supports mapping directives straight into the server's state, enabling administrators to toggle Auth requirements (requirepass), directories, memory limits, and persistence rules exactly like a native Redis installation.
Features a built-in authentication locking mechanic. When configured, the core command handler guards against unauthorized access, only letting AUTH and COMMAND bypass the filter until the client successfully authenticates with the configured password.
I'm a freelance software developer who builds AI Agents, workflows, websites, and mobile apps for businesses. If you're interested in something like that, book a call below and let's get to work. In the meantime, here's a couple social links where you can stalk me. ๐
If you've got a cool project or opportunity and you want me to be a part of it, set up a free meeting with me here, and let's talk. ๐