A Redis-compatible in-memory database built from scratch in Python. Supports replication, blocking reads, lists, streams, sorted sets, and pub/sub.
-
Core Commands: PING, ECHO, SET, GET, INCR
-
Lists: LPUSH, RPUSH, LPOP, BLPOP, LRANGE, LLEN
-
Streams: XADD, XRANGE, XREAD
-
Sorted Sets: ZADD, ZRANGE, ZRANK, ZCARD, ZSCORE, ZREM
-
Pub/Sub: SUBSCRIBE, PUBLISH, UNSUBSCRIBE
-
Replication: Implements REPLCONF, PSYNC, and WAIT
-
Config & Introspection: CONFIG GET, INFO replication, KEYS
-
Full RESP Protocol support
git clone https://github.com/YOUR_USERNAME/redis-clone.git
cd redis-clone
- If on Windows, install and type
wsland enter first.
python3 -m app.main
redis-cli -p 6379
- PING # -> +PONG
- ECHO "Hello" # -> "Hello"
- SET key value [PX 1000] # -> +OK
- GET key # -> "value"
- INCR key # -> (integer) 1
- LPUSH mylist "a" # -> (integer) 1
- RPUSH mylist "b" # -> (integer) 2
- LRANGE mylist 0 -1 # -> ["a", "b"]
- LLEN mylist # -> (integer) 2
- LPOP mylist # -> "a"
- BLPOP mylist 0 # -> ["mylist", "b"] # Blocks if empty
- XADD mystream * field value # -> "1689851248173-0"
- XRANGE mystream - + # -> list of entries
- XREAD STREAMS mystream 0 # -> list of new entries
- XREAD BLOCK ms STREAMS mysteam id #-> Read entries from stream (blocking supported)
- SUBSCRIBE channel # -> "subscribe"
- PUBLISH channel "Hello" # -> (integer) number of subscribers
- UNSUBSCRIBE channel # -> "unsubscribe"
- ZADD myzset 1 "one" # -> (integer) 1
- ZRANGE myzset 0 -1 # -> ["one"]
- ZCARD myzset # -> (integer) 1
- ZRANK myzset "one" # -> (integer) 0
- ZSCORE myzset "one" # -> "1"
- ZREM myzset "one" # -> (integer) 1
- TYPE key # -> "string" | "list" | "stream" | "zset"
- KEYS * # -> ["key1", "key2"]
- CONFIG GET dir|dbfilename # -> ["dir", "/tmp" | "dbfilename", "dump.rdb"]
- INFO replication # -> replication info
- WAIT numreplicas timeout # -> Wait for replicas to acknowledge
python3 app/main.py --port 6379
python3 app/main.py --port 6380 --replicaof localhost 6379
-
PSYNC for initial data sync
-
REPLCONF for replica handshake
-
WAIT to ensure writes propagate to replicas
-
Language: Python 3
-
Networking: TCP Sockets
-
Protocol: RESP (Redis Serialization Protocol)
Add RDB/AOF persistence
Improve async I/O for concurrency
Support pattern-based pub/sub
Inspired by the Redis architecture and built to deeply understand data structures, networking, and replication internals.

