This project implements a simplified version of Redis as an educational exercise, inspired by the "Build Your Own Redis" guide. The goal is to deepen the understanding of key components like hash tables, AVL trees, and client-server communication using sockets.
- Client-Server Architecture: Communication using sockets with a basic protocol for sending and receiving requests.
- Core Commands:
SET key value
– Store a key-value pair.GET key
– Retrieve a value associated with a key.DEL key
– Delete a key-value pair.KEYS
– Retrieve all stored keys.
- HashMap Implementation: Efficient key-value storage using a progressive resizing hash table.
- AVL Tree: Support for ordered operations and balanced data structure management.
Ensure the following tools and libraries are installed:
- C++ Compiler:
g++
orclang++
- System Libraries:
arpa/inet.h
,sys/socket.h
(for UNIX/Linux environments) - Development Environment: A Linux or MacOS terminal (tested on Linux)
.
├── README.md # Documentation
├── client.cpp # Client implementation
├── server.cpp # Server implementation
├── libraries
│ ├── AVL.cpp # AVL Tree source
│ ├── AVL.h # AVL Tree header
│ ├── AVLTest.cpp # AVL Tree tests
│ ├── Common.h # Common macros and helpers
│ ├── HashTable.cpp # Hash table source
│ ├── HashTable.h # Hash table header
│ ├── HelperLibrary.cpp # Helper functions (I/O, errors)
│ ├── HelperLibrary.h # Helper header
│ └── ZSet.h # ZSet stub (for future use)
├── dump.rdb # Example dump file for persistence
├── myOwnRedis # Executable server binary
└── client # Executable client binary
g++ -std=c++11 -o server server.cpp libraries/HashTable.cpp libraries/AVL.cpp libraries/HelperLibrary.cpp
g++ -std=c++11 -o client client.cpp libraries/HelperLibrary.cpp
Start the server on port 1234:
./server
Use the client to connect and interact with the server:
./client SET mykey "HelloWorld"
./client GET mykey
./client DEL mykey
./client KEYS
./client SET foo "bar"
Connected to the server!
(Nil)
./client GET foo
Connected to the server!
(str) bar
./client DEL foo
Connected to the server!
(int) 1
./client KEYS
(arr) len = 1
foo
(arr) end
The AVL Tree implementation is tested in AVLTest.cpp. To run tests:
g++ -std=c++11 -o AVLTest libraries/AVLTest.cpp libraries/AVL.cpp
./AVLTest
- Build Your Own Redis – The inspiration and guidance for this project.
- Redis – The original in-memory key-value store that inspired this implementation.
- C++ Standard Library – Leveraging tools like sockets, hash tables, and balanced trees to understand core systems programming concepts.
- Special thanks to resources and communities that provided insights into data structures, client-server architectures, and best practices in C++ development.
- Build Your Own Redis: https://build-your-own.org/redis/
- Redis Official Documentation: https://redis.io/documentation
- C++ Reference for
<cstdint>
and<cstddef>
: https://en.cppreference.com - Socket Programming Basics: Beej's Guide to Network Programming