Carrot is a Redis-like key-value database that supports both basic KV operations and sorted sets. It implements a subset of Redis commands with a focus on simplicity and efficiency.
Before building Carrot, ensure you have the following installed:
- CMake (version 3.0 or higher)
- Make
- GCC or Clang compiler
- Unix-like operating system
- Clone the repository:
git clone [email protected]:devansh-srv/carrot.git
cd carrot- Give execution permission to the build script:
chmod +x build.sh- Build the project:
./build.shStart the server:
cd build
./binThis will initialize CMake and build both the server and client binaries.
The client can be used to send commands to the server:
cd build
./client <command>Example:
./client get mykey- Clone the repository:
git clone [email protected]:devansh-srv/carrot.git
cd carrot- Build docker image:
docker build -t carrotStart the server using docker image:
docker run --name carrot-server -p 12345:12345 carrotdocker exec -it carrot-server sh Commands:
/app/client get mykey- GET - Retrieve a value by key
./client localhost 6379 get mykey- SET - Set a value for a key
./client localhost 6379 set mykey myvalue- DEL - Delete a key-value pair
./client localhost 6379 del mykey- KEYS - List all stored keys
./client localhost 6379 keys- ZADD - Add a scored element to a sorted set
./client localhost 6379 zadd myset 1.5 element1- ZREM - Remove an element from a sorted set
./client localhost 6379 zrem myset element1- ZSCORE - Get the score of an element
./client localhost 6379 zscore myset element1- ZRANK - Get the rank of an element
./client localhost 6379 zrank myset element1- ZQUERY - Query elements in a sorted set
./client localhost 6379 zquery myset 1.0 "" 0 10Parameters:
- key: The sorted set key
- score: Minimum score to start from
- name: Minimum element name to start from
- offset: Number of elements to skip
- limit: Maximum number of elements to return
- PEXPIRE - Set the ttl value for any key in msec
./client localhost 6379 pexpire myset 1000 - PTTL - Get the ttl for any key
./client localhost 6379 pttl myset- Written in C
- Uses non-blocking I/O
- Implements an event loop using poll()
- Supports concurrent client connections
- Uses FNV hash for key hashing
- Implements AVL trees for sorted sets
- Thank you Vansh Jangir and Amritanshu Darbari for coming up with this amazing name.
- Thank you to Erik Demaine for this amazing lecture on data structure augmentation that helped me in understanding AVL trees and range queries.
- MITOCW Lecture
- Also big thanks to 0xAX for the amazing repo that taught me about intrinsic data structures
- linux-insiders
Feel free to submit issues and pull requests.