Skip to content

devansh-srv/carrot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Carrot

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.

Prerequisites

Before building Carrot, ensure you have the following installed:

  • CMake (version 3.0 or higher)
  • Make
  • GCC or Clang compiler
  • Unix-like operating system

Building from Source

  1. Clone the repository:
git clone git@github.com:devansh-srv/carrot.git
cd carrot
  1. Give execution permission to the build script:
chmod +x build.sh
  1. Build the project:
./build.sh

This will initialize CMake and build both the server and client binaries.

Running the Server

Start the server by specifying a port number:

cd build
./bin <port>

Example:

cd build
./bin 6379

Using the Client

The client can be used to send commands to the server:

cd build
./client <hostname> <port> <command>

Example:

./client localhost 6379 get mykey

Supported Commands

Basic Key-Value Operations

  1. GET - Retrieve a value by key
./client localhost 6379 get mykey
  1. SET - Set a value for a key
./client localhost 6379 set mykey myvalue
  1. DEL - Delete a key-value pair
./client localhost 6379 del mykey
  1. KEYS - List all stored keys
./client localhost 6379 keys

Sorted Set Operations

  1. ZADD - Add a scored element to a sorted set
./client localhost 6379 zadd myset 1.5 element1
  1. ZREM - Remove an element from a sorted set
./client localhost 6379 zrem myset element1
  1. ZSCORE - Get the score of an element
./client localhost 6379 zscore myset element1
  1. ZRANK - Get the rank of an element
./client localhost 6379 zrank myset element1
  1. ZQUERY - Query elements in a sorted set
./client localhost 6379 zquery myset 1.0 "" 0 10

Parameters:

  • 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

Cache Evinction Operations

  1. PEXPIRE - Set the ttl value for any key in msec
./client localhost 6379 pexpire myset 1000 
  1. PTTL - Get the ttl for any key
./client localhost 6379 pttl myset

Technical Details

  • 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

Acknowledgement

Contributing

Feel free to submit issues and pull requests.

Releases

No releases published

Packages

No packages published

Languages