An in-memory Key-Value server written in C++, developed using a modular Object-Oriented Programming (OOP) architecture. The project supports concurrent multi-threading, thread-safe synchronization, and disk data persistence.
The project is organized into separate modules for networking and data management:
mini-redis-cpp/ ├── .vscode/ # VS Code editor settings ├── .gitignore # Git rules to ignore binaries and temporary files ├── Database.h # Database class declaration (data interface) ├── Database.cpp # Implementation of storage, synchronization, and disk I/O ├── Server.h # Server class declaration (network interface) ├── Server.cpp # Implementation of TCP sockets and thread management ├── main.cpp # Application entry point ├── database.txt # Persistence file (local data storage) ├── main.exe # Compiled executable └── README.md # Project documentation
- OOP Architecture: Clear separation between the data module (Database) and the network module (Server).
- Thread Safety: Data protection during concurrent access using std::mutex and std::lock_guard.
- Multi-threading: Each connected client is handled on a dedicated thread (std::thread).
- Persistence: Automatic saving of changes to database.txt and automatic loading into memory upon server startup.
- TCP Protocol: Communication via Winsock2 sockets on port 6379.
- SET : Stores the key-value pair in memory and on disk.
- GET : Returns the value associated with the key or an error message.
- DEL : Removes the key from memory and updates the file.
- EXIT : Closes the current client connection.
- C++ compiler (MinGW / g++) with C++11 support or newer.
- Winsock2 library (ws2_32) on Windows systems.
Open a terminal in the project directory and run:
g++ *.cpp -o main.exe -lws2_32
Once compiled successfully, start the server:
.\main.exe
The server will listen for incoming connections on port 6379.
You can connect using a RAW socket client such as PuTTY:
- Host Name: 127.0.0.1 or localhost
- Port: 6379
- Connection type: Raw
- Click Open and send interactive commands (SET, GET, DEL, EXIT).