Skip to content

nemish11/redis-cpp

Repository files navigation

redis-cpp

A custom implementation for Redis using C++ and AVL Tree .

Table Of Content

  1. Environment
  2. Description.
  3. Usage tips.
  4. Implementation Details.
  5. Testing Details.
  6. Command Line Interface.

1. Environment

Language: C++ 11
OS: macOS Catalina 10.15.3
Tools: VS code (1.41.1)

2. Description

Implemented following Redis commands:

  1. GET: Get the value of key
  2. SET: Set key to hold the string value
  3. EXPIRE: Set a timeout on key. After the timeout has expired, the key will automatically be deleted
  4. ZADD: Adds all the specified members with the specified scores to the sorted set stored at key
  5. ZRANK: Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high
  6. ZRANGE: Returns the specified range of elements in the sorted set stored at key
  7. ZREVRANK: Returns the rank of member in the sorted set stored at key, with the scores ordered from high to low
  8. ZCARD: Returns the sorted set cardinality (number of elements) of the sorted set stored at key.
  9. ZSCORE: Returns the score of member in the sorted set at key

3. Usage tips

Step 1: Clone Repo

git clone https://github.com/nemish11/redis-cpp

Step 2: Compile and Run client.cpp file

g++ --std=c++11 client.cpp
./a.out

Step 3: Change content of client.cpp and perform step 2

Note: Threading is used to clear expired keys. In the case of segmentation fault, running the code twice will create the thread.

4. Implementation Details

To manage sorted set of keys AVL tree is implemented.
AVL support insert, delete, getRank all operations in O(logN).

In Case of segmentation fault, comment following code in redis.h:

Redis() 
{        
    threadStatus = true;  // set thread status
    t1 = thread(&Redis::freeExpiredKey, this); // start thread for cleaning expire key 
    t1.detach(); // run thread in background
}
~Redis()
{ 
    threadStatus = false; // complete execution of thread
    t1.~thread();
} 

5. Testing Details

test_redis.cpp contains unit test cases for each command. To run test cases enter below commands:

g++ --std=c++11 test_redis.cpp
./a.out

testGET( ) method will test GET command.
same naming convension for other commands.
New Redis instance will be created per method.

6. Command Line Interface

To use CLI run following commands:

g++ --std=c++11 command_line_interface.cpp
./a.out

Type HELP command to check usage of each command.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages