This is a replication of Redis built using C++. This project was made by following the book "Build Your Own Redis" by James Smith. This project was made to understand the internals of Redis and how it works. Think of it like a case study rather than a full on project.
Note: This project uses syscalls on Linux and will not work on other operating systems.
- A server that stores the database in memory
- A client that can interact with the server
- The database stores key-value pairs
- The values can either be strings or a sorted set
- The design choices that Redis made
- How to build a tcp server client model in C++
- The usage of Event Loops to handle multiple clients
- How to avoid latency spikes by spreading work over multiple iterations of the event loop
- Implementing multiple datastructures like hashmap (chaining), AVL tree etc
- Multi-threading for handling long running tasks like deleting a large sorted set
You can build the binaries using CMake.
mkdir build
cd build
cmake ..
makeThis will place the server and client binaries in the bin directory.
Start by running the server binary. Next, run the client binary. The client will establish a connection to the server and you will be able to run commands.
get <key>: Get the value of a key.set <key> <value>: Set the value of a key.del <key>: Delete a key.pexpire <key> <milliseconds>: Set a key to expire after a certain amount of time.pttl <key>: Get the time to live of a key in milliseconds.keys: Get all the keys in the database.
zadd <key> <score> <value>: Add a value to a sorted set with a score (set is sorted by score).zrem <key> <value>: Remove a value from a sorted set.zscore <key> <value>: Get the score of a value in a sorted set.zquery <key> <score> <value> <offset> <limit>: Get limit values in a sorted set starting from given value + offset.