Skip to content

Repository files navigation

Redis Server in Python

A Redis-compatible server written in Python. The project implements the RESP protocol, an async TCP server, an in-memory Redis-style data store, command dispatching, blocking list operations, and basic transaction support.

This is a learning-focused implementation, but the code is organized like a real server project: protocol parsing, command handling, storage, connection handling, and error types are separated into clear modules.

Features

  • Async TCP server using asyncio
  • RESP encoder and stream parser
  • In-memory key-value storage with optional expiry
  • String commands:
    • PING
    • ECHO
    • SET
    • GET
    • INCR
  • List commands:
    • LPUSH
    • RPUSH
    • LPOP
    • LLEN
    • LRANGE
    • BLPOP
  • Transactions:
    • MULTI
    • EXEC
    • DISCARD
  • Interactive client file for local testing

Requirements

  • Python >= 3.14
  • uv

The project currently has no third-party runtime dependencies.

Project Structure

app/
  main.py                  # Application entry point
  client.py                # Interactive test client
  commands/                # Redis command implementations
    base.py
    registry.py
    cmd_connection.py
    cmd_string.py
    cmd_list.py
  core/                    # Protocol, storage, RESP types, errors
    errors.py
    protocol.py
    resp_types.py
    store.py
  server/                  # TCP server and connection handling
    connection.py
    tcp_server.py

Setup

Clone the repository:

git clone <repo-url>
cd codecrafters-redis-python

Install uv if it is not already available:

curl -LsSf https://astral.sh/uv/install.sh | sh

Verify the environment:

uv run python --version

Running the Server

Start the Redis-like server:

./your_program.sh

By default, the server listens on:

127.0.0.1:6379

You can also run it directly:

uv run --quiet -m app.main

Testing with the Local Client

In another terminal, start the interactive client:

uv run python -m app.client

Example session:

redis> PING
PONG

redis> SET name vikash
OK

redis> GET name
vikash

redis> LPUSH numbers one two three
3

redis> LPOP numbers
three

Quoted values are supported:

redis> ECHO "hello world"
hello world

Transaction Example

redis> MULTI
OK

redis> SET user:1 vikash
QUEUED

redis> GET user:1
QUEUED

redis> EXEC
*2
+OK
$6
vikash

DISCARD clears a pending transaction:

redis> MULTI
OK

redis> SET temp value
QUEUED

redis> DISCARD
OK

Blocking List Example

Run this in one client:

redis> BLPOP jobs 0

Then from another client:

redis> LPUSH jobs build

The blocked client receives the pushed value.

Development Checks

Compile all Python files:

python3 -m compileall app

Run the server locally:

./your_program.sh

Run the client locally:

uv run python -m app.client

Current Limitations / pending features

  • Data is stored in memory only.
  • Persistence/RDB support is not implemented yet.
  • Replication is not implemented yet.
  • Pub/Sub is not implemented yet.
  • This project targets a focused subset of Redis behavior rather than full Redis compatibility.

Notes

This project started from the CodeCrafters Redis challenge, but rightnow it is a standalone Python project with far more features than the challenge and can be run locally without the CodeCrafters platform.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages