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 git@github.com:devansh-srv/carrot.git
cd carrot
- Give execution permission to the build script:
chmod +x build.sh
- Build the project:
./build.sh
This will initialize CMake and build both the server and client binaries.
Start the server by specifying a port number:
cd build
./bin <port>
Example:
cd build
./bin 6379
The client can be used to send commands to the server:
cd build
./client <hostname> <port> <command>
Example:
./client localhost 6379 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 10
Parameters:
key
: The sorted set keyscore
: Minimum score to start fromname
: Minimum element name to start fromoffset
: Number of elements to skiplimit
: 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.