Skip to content

Aquib-Nawaz/codecrafters-redis-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codecrafters Redis Challenge – C Implementation

This repository contains a minimal Redis server implementation written in C for the Codecrafters Redis challenge.

Features

  • TCP server: Accepts connections from Redis clients.
  • RESP protocol parsing: Handles the Redis Serialization Protocol for requests and responses.
  • Key-value store: Supports basic Redis commands (PING, ECHO, SET, GET).
  • Key expiry (TTL): Supports time-to-live for keys.
  • Streams and Replication: Includes stream and replication modules for more advanced Redis features.

Folder Structure

app/
├── hashset.c       # Hashset (key-value store) implementation
├── hashset.h
├── message.c       # Handles message/request/response logic
├── message.h
├── parser.c        # RESP protocol parser
├── parser.h
├── replication.c   # Redis replication logic
├── replication.h
├── server.c        # TCP server and main event loop
├── stream.c        # Stream data-type and logic
├── stream.h

Getting Started

Prerequisites

  • GCC or Clang (C99 compatible)
  • make utility
  • Linux/macOS (Windows support may vary)
  • redis-cli or netcat for manual testing

Build And Run

./spawn_redis_server.sh

By default, the server listens on port 6379.

Connect & Test

Using redis-cli:

redis-cli -p 6379 ping
redis-cli -p 6379 set foo bar
redis-cli -p 6379 get foo

Or with nc:

echo -en "*1\r\n$4\r\nPING\r\n" | nc localhost 6379

Extending

  • Add new commands in message.c and update protocol handling in parser.c.
  • Stream and replication features can be extended by editing stream.c and replication.c.

License

MIT License


Inspired by Redis. Built for the Codecrafters Redis challenge.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages