This repository contains a minimal Redis server implementation written in C for the Codecrafters Redis challenge.
- 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.
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
- GCC or Clang (C99 compatible)
makeutility- Linux/macOS (Windows support may vary)
redis-cliornetcatfor manual testing
./spawn_redis_server.shBy default, the server listens on port 6379.
Using redis-cli:
redis-cli -p 6379 ping
redis-cli -p 6379 set foo bar
redis-cli -p 6379 get fooOr with nc:
echo -en "*1\r\n$4\r\nPING\r\n" | nc localhost 6379- Add new commands in
message.cand update protocol handling inparser.c. - Stream and replication features can be extended by editing
stream.candreplication.c.
MIT License
Inspired by Redis. Built for the Codecrafters Redis challenge.