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.
- Async TCP server using
asyncio - RESP encoder and stream parser
- In-memory key-value storage with optional expiry
- String commands:
PINGECHOSETGETINCR
- List commands:
LPUSHRPUSHLPOPLLENLRANGEBLPOP
- Transactions:
MULTIEXECDISCARD
- Interactive client file for local testing
- Python
>= 3.14 uv
The project currently has no third-party runtime dependencies.
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
Clone the repository:
git clone <repo-url>
cd codecrafters-redis-pythonInstall uv if it is not already available:
curl -LsSf https://astral.sh/uv/install.sh | shVerify the environment:
uv run python --versionStart the Redis-like server:
./your_program.shBy default, the server listens on:
127.0.0.1:6379
You can also run it directly:
uv run --quiet -m app.mainIn another terminal, start the interactive client:
uv run python -m app.clientExample 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
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
Run this in one client:
redis> BLPOP jobs 0
Then from another client:
redis> LPUSH jobs build
The blocked client receives the pushed value.
Compile all Python files:
python3 -m compileall appRun the server locally:
./your_program.shRun the client locally:
uv run python -m app.client- 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.
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.