Skip to content

kush-jain/redis-python

Repository files navigation

Basic Redis Implementation

In this, implement basic Redis implementation by creating Redis SERVER. Idea is not to create REDIS, but learn the key concepts in REDIS.

Inspiration

Inspired by codecrafters.

Dependencies

Tested with Python 3.9+ Requires pytest and pytest-asyncio if you need to run local test cases

How to use

Server

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

Client

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

Functionalities

This Redis server can handle multiple concurrent clients. Clients can send multiple requests as needed

Commands

  1. PING and ECHO commands
  2. SET Command with limited expiry support. Only ACTIVE expiry possible
  3. GET and TYPE Command
  4. INCR
  5. Stream commands: XADD, XRANGE, XREAD
  6. EXEC, MULTI, DISCARD support
  7. KEYS Command
  8. Limited CONFIG GET Command
  9. For GET and KEYS, can read from RDB file. Defaults to DB zero
  10. INFO Command basic support
  11. WAIT Command

Command Line Options

  1. Custom DIR and DBFILENAME parameters to specify RDB file location
  2. PORT

RDB Parser

Only support RDB v3

  1. Read Metadata
  2. Can parse any number of keys
  3. Only work with string values for now. Does not work with compressed strings. Does work with integers encoded as strings
  4. Does not support writing to RDB

Replication

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

Stream Support

Basic stream commands are supported.

Transaction Support

Support MULTI, EXEC and DISCARD for transaction Does error handling, and works with multiple transactions

References and Help

Socket

Worked directly from source

Async Programming

RDB File Format and Parsing

Redis Protocol

About

Working Redis Server made in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published