Mini Redis is a custom implementation of an in-memory database, engineered from the ground up in C. Designed to demonstrate low-level systems programming, custom memory management, and TCP/IP network socket communication.
This project explores the fundamental mechanics behind modern caching systems by implementing core database operations (CRUD), employing AVL trees for guaranteed O(log n) time complexities, and handling client-server network protocols autonomously without relying on high-level external frameworks.
- 🧠 In-Memory Storage Engine: Blazing-fast state retention utilizing heavily optimized manual memory allocations.
- 🌳 AVL Tree Indexing: Ensures that all search, insert, and delete operations strictly adhere to O(log n) time complexities through automatic self-balancing tree rotations.
- 🌐 Custom Socket Networking: Implements raw TCP/IP sockets for robust client-server architecture.
- 🐍 Lightweight Python Client: Includes a custom protocol wrapper written in Python for effortless database integration and testing.
- 🛡️ Fault Tolerance & Memory Safety: Architected to mitigate memory leaks with rigorous Valgrind-tested allocations and graceful crash-handling policies.
- 📝 High-Performance Logging: Employs an intelligent circular-buffer logging strategy (syslog and console modes) for bottleneck-free analytics.
- Build the container:
make docker-build
- Run integration tests inside isolated container:
make docker-test
- Spin up the server:
docker run -p 45234:45234 mini-redis
-
Compile via Make:
make
-
Run the Server:
./mini-redis [-p port] [-i] [-s]
-p port: Specify network port (default:45234)-i: EnableINFOlogging verbosity (default:ERROR)-s: Bind tosysloginstead of standard console output.
-
Run Unit Tests & Cleanup:
make test make clean
The server communicates via standard JSON payloads over TCP.
| Operation | Command Example | Description |
|---|---|---|
| SET | {"operation": "SET", "key": "mykey", "value": "myvalue"} |
Inserts or updates a key-value pair. |
| GET | {"operation": "GET", "key": "mykey"} |
Retrieves the value bound to the key. |
| DEL | {"operation": "DEL", "key": "mykey"} |
Removes the key and frees memory. |
To guarantee memory safety and architectural integrity, the project is equipped with a rigorous test suite:
- Tree Integrity: Validates strict AVL height rules and rebalancing (Left-Left, Right-Right, Left-Right, Right-Left).
- Leak Detection: Monitors dangling pointers during rapid CRUD cycles.
- Fault Tolerance: Randomizes socket closures and invalid payloads to ensure the main thread never crashes.
Run the test suite safely via Docker:
make docker-test- [ ] SQL Parser: Implementation of Abstract Syntax Trees (AST) for relational-style complex queries.
- [ ] Concurrency: Migrating the event loop to
epollorkqueuefor high-concurrency non-blocking I/O. - [ ] Disk Persistence: AOF (Append Only File) logging for crash recovery.
Pull requests are welcome! If you want to optimize the AVL rotations or add multi-threading, feel free to submit a PR.