A fast, minimal, and extensible key-value store written in C++ for UNIX-based systems. Built with low-level control in mind, it uses custom non-blocking sockets and an efficient hashtable for performance. The store supports multiple types, including ordered list types using red-black trees, and introduces TTL (Time-To-Live) support for expirable keys. There are no external dependencies.
The architecture is designed for simplicity and speed, focusing on deep control of memory, sockets, file I/O and multi-threading.
- Low-level non-blocking socket server using
poll,bind, andsetsockopt - Custom non-blocking event loop, no threads or callbacks
- Strong type system:
int64_t,double,std::string, and their list counterparts - Ordered list types (
list<int>,list<double>,list<string>) implemented using red-black trees for efficientO(log n)operations - TTL (Time-To-Live) support for scalar and list values
- Optional persistence with binary dump/load support
- Log file support (enabled by default)
- Python script for load testing
- Built with CMake for easy build setup
- Clean codebase separation (client, server, shared logic)
- Producer-Consumer Pattern for logging using Semaphores
The client sends requests as a sequence of strings.
Format:
[n] [len1][str1] [len2][str2] ... [lenN][strN]
Where:
nis the number of strings.- Each string is prefixed with its length.
This format is simple to parse and avoids complex serialization logic.
The server is launched via command-line arguments.
Default values:
- Port:
3000 - Persistence:
1(enabled) - Log Enabled:
1(enabled) - Data file:
data/storage.dat - Log file:
logs/operations.log
project_root/
├── client/ # Client application (client.cpp)
├── include/ # Server headers
├── script/ # Python load testing script
│ └── main.py
├── shared/ # Shared code between client and server
├── src/ # Core server source code
├── CMakeLists.txt # CMake build script
└── .gitignore # Git ignore file
Supported Platforms: UNIX (Linux/macOS). Windows is not supported.
git clone https://github.com/HusseinSerag/your-repo.git
cd your-repomkdir build && cd build
cmake ..
make./server_exec # Uses default configuration
# Or manually:
./server_exec <port> <persistence> <data_file> <log_file> <log_enabled>
# Example:
./server_exec --port=3000 --persistence=1 --data_file=data/storage.dat --log_file=logs/operations.log --log_enabled=1./clientcd script
python3 main.py- Malformed or invalid operations result in connection termination.
- Division by zero and similar invalid operations raise exceptions.
- The log file records all operations and results (if logging is enabled).
- TTL keys are automatically purged after expiration.
The script/main.py simulates multiple clients performing rapid operations to benchmark the server. On a local test, the server handled 19,000 SET operations per second.
Built with care by HusseinSerag. The project emphasizes clean, low-level design, and extensibility—adding new types or extending functionality is straightforward.
Feel free to fork and submit a PR. Suggestions, issues, and improvements are always welcome.
MIT License.