Inspired by the book "Build your own Redis in C/C++" by James Smith. The book implements in C basically which goes pretty low level.
A custom in-memory key-value store inspired by Redis, implemented in C++. This project includes custom implementations of various data structures and provides a Redis-like interface for storing and retrieving data.
- In-memory key-value storage
- TTL (Time-To-Live) expiration
- Non-blocking I/O using epoll
- Socket-based communication
- Multithreaded design for concurrent operations
- Basic Commands: SET, GET, DEL, EXISTS, EXPIRE, TTL, DBSIZE, FLUSHDB
- Sorted Set Commands: ZADD, ZREM, ZSCORE, ZRANGE, ZRANGEBYSCORE, ZRANK, ZCARD
- Hash Table: For primary key-value storage
- AVL Tree: For efficient sorted data structures
- Heap: For TTL management
- Sorted Set: Implemented using AVL tree and hash map
# Create a build directory
mkdir build && cd build
# Generate build files
cmake ..
# Build the project
make
# Run the server
./my_redis_server [port]The project includes a comprehensive Python test script that tests all functionality:
# Navigate to the tests directory
cd tests
# Run the tests
python3 test_redis.pyThe project is organized into several components:
- Data Structures: Custom implementations of hash table, AVL tree, heap, and sorted set
- Storage Engine: Core storage functionality with TTL management
- Command Handler: Processes Redis-like commands
- Server: Handles client connections and network I/O
- Non-blocking I/O for handling multiple connections
- Efficient data structures for different operations
- Thread-safe implementations for concurrent access
- Optimized memory usage
- More Redis commands (Lists, Sets, Hashes)
This project was inspired by Redis, the popular in-memory data structure store.
"Build your own Redis in C/C++" by James Smith