Skip to content

avrumnoor/redispython

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Redis Clone in Python 🐍

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).

βœ… Features Implemented

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

πŸ“¦ RESP Protocol

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

🧠 Internal Logic

  • Data is stored in a Python dictionary: dict_store
  • Each key maps to a tuple: (value, expiry_timestamp)
  • Expiry is handled using the PX argument, with expiry checked on each GET

πŸš€ How to Run

python3 main.py

The server listens on port 6379.

πŸ› οΈ Project Structure

  • main.py: Entry point
  • handle_client_connection(): Main handler for client commands
  • handle_get() / handle_set(): Logic for GET and SET
  • parse_and_decode_data(): RESP parsing logic

πŸ“š Learnings

  • Sockets and multi-threaded server setup
  • Binary protocol parsing (RESP)
  • State handling with TTL (PX)
  • Importance of accurate time-based expiry logic

πŸ“Œ Notes

  • This is not production Redis.
  • Built for educational purposes and to learn low-level networking.

Built with ❀️ by Avrum Noor LinkedIn X (formerly Twitter) Follow

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published