This is a toy implementation of a Redis server written in Python. The goal is to implement a subset of Redis' functionality using the Redis Serialization Protocol (RESP).
| Command | Description |
|---|---|
PING |
Responds with PONG |
ECHO |
Echoes back the given message |
SET |
Stores a key-value pair |
GET |
Retrieves the value for a given key |
PX |
Optional SET modifier to set expiry in millis |
This project parses and responds using the Redis Serialization Protocol (RESP). Example:
*2\r\n$4\r\nECHO\r\n$5\r\nhello\r\n
Represents:
ECHO hello
- Data is stored in a Python dictionary:
dict_store - Each key maps to a tuple:
(value, expiry_timestamp) - Expiry is handled using the
PXargument, with expiry checked on eachGET
python3 main.pyThe server listens on port 6379.
main.py: Entry pointhandle_client_connection(): Main handler for client commandshandle_get()/handle_set(): Logic forGETandSETparse_and_decode_data(): RESP parsing logic
- Sockets and multi-threaded server setup
- Binary protocol parsing (RESP)
- State handling with TTL (PX)
- Importance of accurate time-based expiry logic
- This is not production Redis.
- Built for educational purposes and to learn low-level networking.
Built with β€οΈ by Avrum Noor
![]()