Redis Clone · Java
Capis
A Redis-like in-memory key-value store written from scratch in Java to understand the moving parts behind a networked data server.
> SET greeting hello
OK
> GET greeting
"hello"
> TTL greeting
42
Notes from the build
The challenge
The difficult part was the low-level design. The project grew from a simple key-value store into a system with several data types, many commands, configuration, transactions, expiry, and eviction. The code needed clear boundaries before more features could be added safely.
How I solved it
- A Bootstrap composition root wires the server, configuration, store, cache, and command registry.
- AppConfig and ConfigLoader validate startup options such as port, capacity, eviction policy, and expiry sweep budget.
- A sealed Value hierarchy represents strings, lists, sets, hashes, and sorted sets.
- CommandRegistry dispatches 37 commands, while CommandHandler handles MULTI, EXEC, and DISCARD.
Expiry and eviction
Keys can expire through EXPIRE, TTL, PERSIST, and SETEX. Expired entries are removed lazily during access and by a randomized maintenance sweep on the event loop. The cache can use LRU or LFU eviction through the same abstraction.
The server layer
Capis uses a single-threaded, non-blocking java.nio event loop. Each connection owns an input buffer, partial RESP reads remain buffered, and pipelined commands can be decoded from one write.
What remains out of scope
Capis is a learning project, not a Redis replacement. It does not include persistence, replication, authentication, or clustering, and some configuration values are validated but not wired yet.
Keep exploring
