Skip to content

Dive into a JavaScript rendition of the Codecrafters Redis Challenge. Beyond the basics, this repo amps up Redis functionalities with benchmarks and extensive testing. It is built for enthusiasts by an enthusiast!

Notifications You must be signed in to change notification settings

HMarzban/codecrafters-redis-javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codecrafters Redis in JavaScript

Codecrafters Challenge Progress

Welcome! This is my take on the Codecrafters Redis Challenge Redis Challenge. I've delved deep into the heart of Redis and ended up crafting my own little version in JavaScript. Dive in and check it out!

Introduction

Welcome to my solution for the Codecrafters Redis challenge! In this repository, I've created a toy Redis clone that not only handles the basic commands like PING, GET, and SET but also includes an extended SET of features that was not in the challenge. With benchmarking tools and extensive testing, this repository is meant to be both an educational resource and a fun exploration into the world of Redis.

Features

SET Command

Syntax

SET key value [NX | XX] [GET] [EX seconds | PX milliseconds |
  EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL]

Supportet Options:

  • EX seconds -- Set the specified expire time, in seconds.
  • PX milliseconds -- Set the specified expire time, in milliseconds.
  • EXAT timestamp-seconds -- Set the specified Unix time at which the key will expire, in seconds.
  • PXAT timestamp-milliseconds -- Set the specified Unix time at which the key will expire, in milliseconds.
  • NX -- Only set the key if it does not already exist.
  • XX -- Only set the key if it already exists.
  • KEEPTTL -- Retain the time to live associated with the key.
  • GET -- Return the old string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value stored at key is not a string.

Other Commands

  • DEL -- Delete a key
  • ECHO -- Echo the given string
  • TTL -- Get the time to live for a key
  • PING -- Ping the server
  • EXIT -- Quit the server

Additional Features

  • Robust Testing: Leveraged the test.sh script to ensure all command combinations operate as expected.
  • Performance Benchmarking: Introduced benchmark.sh for performance measurement and analysis.
  • Scalable Workers: Easily scale worker processes using environment variables. (nodejs, singel thread give you the best perfomance)

Getting Started

Prerequisites

Ensure Node.js and redis-cli are installed on your machine.

Setup & Running

  1. Clone the Repository:

    git clone https://github.com/HMarzban/codecrafters-redis-javascript.git
  2. Start the Application:

    npm start

To customize the worker count:

  • 4 Workers: npm run start:worker4
  • 2 Workers: npm run start:worker2
  • Single Worker: npm run start:worker1

Testing

Run the test script to validate the command implementations:

npm run test

Benchmarking

Analyze the performance of the system with the benchmarking script:

npm run benchmark

Note: Ensure the node application is hitting in the background before initiating tests or benchmarks.

I hope you find this project insightful and get a deeper understanding of how Redis works in the background. If you're curious like me, dive in and have fun learning!

About

Dive into a JavaScript rendition of the Codecrafters Redis Challenge. Beyond the basics, this repo amps up Redis functionalities with benchmarks and extensive testing. It is built for enthusiasts by an enthusiast!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published