Redis is an open source in-memory key value database which is widely used in applications requiring caching, session storage, rate limiting, and real-time applications due to it's very high read/write performance. In this project, I habe implemented a Redis inspired clone built in C++. It features core database functionality like TCP client-server communication, command parsing, persistence, TTL expiration, multithreading, and thread safe in-memory storage.
- TCP socket server
- Multithreaded client handling
- In-memory key-value store
- Persistence to disk (
dump.rdb) - TTL expiration support
- Thread-safe operations with mutex locks
- Local benchmarking script
PING
SET key value
GET key
DEL key
EXPIRE key seconds
EXISTS key
KEYSmkdir build
cd build
cmake ..
make
./redis_clonenc localhost 6379Run local throughput benchmark:
python3 benchmark.pyExample result:
Requests: 1000
Elapsed: 0.2278s
Requests/sec: 4389.49Achieved 4,000+ requests/sec in local testing.
Client
↓
TCP Socket Server
↓
Command Parser
↓
Database Engine
↓
Persistence Layer
- C++20
- CMake
- POSIX sockets
- std::thread multithreading
- mutex synchronization
- unordered_map in-memory storage
- LRU eviction policy
- Publish/Subscribe messaging
- Replication support
- Additional benchmarking and unit tests
