In this, implement basic Redis implementation by creating Redis SERVER. Idea is not to create REDIS, but learn the key concepts in REDIS.
Inspired by codecrafters.
Tested with Python 3.9+
Requires pytest
and pytest-asyncio
if you need to run local test cases
Server can be up using $./run.sh
Ports etc can be specified as with normal Redis
It is configured to use default port of 6379, which might conflict if you already have redis running on your system
In that case, either configure a custom port using --port <port>
or stop the redis
If you open up server, you can open up multiple clients, and send commands, for example:
$echo -ne '*1\r\n$4\r\nping\r\n' | nc localhost <port>
Or using your favorite programming language
This Redis server can handle multiple concurrent clients. Clients can send multiple requests as needed
- PING and ECHO commands
- SET Command with limited expiry support. Only ACTIVE expiry possible
- GET and TYPE Command
- INCR
- Stream commands: XADD, XRANGE, XREAD
- EXEC, MULTI, DISCARD support
- KEYS Command
- Limited CONFIG GET Command
- For GET and KEYS, can read from RDB file. Defaults to DB zero
- INFO Command basic support
- WAIT Command
- Custom DIR and DBFILENAME parameters to specify RDB file location
- PORT
Only support RDB v3
- Read Metadata
- Can parse any number of keys
- Only work with string values for now. Does not work with compressed strings. Does work with integers encoded as strings
- Does not support writing to RDB
Handshake for master-slave replication is in place. Do basic replication - capable of single or multiple replication. Supports WAIT command and master commands to propogate to replicas
Basic stream commands are supported.
Support MULTI, EXEC and DISCARD for transaction Does error handling, and works with multiple transactions
Worked directly from source
- Event Loop by Philip Roberts is an excellent introduction to this concept.
- RealPython Resources: https://realpython.com/python-concurrency/ and https://realpython.com/async-io-python/
- https://rdb.fnordig.de/file_format.html - This was almost always open while I was working on the parsing logic for RDB
- RDB Parser Tool This repo served as reference whenever I hitted a wall