Skip to content

biswajeetdev/rdb-alpha

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rdb-alpha

Python asyncio Redis Protocol

A Redis-protocol-compatible in-memory key-value store built from scratch in Python — no dependencies beyond the standard library.

Works with redis-cli, any Redis client library, and the included test suite.

Supported commands

Category Commands
Basic PING, ECHO, SET [EX], GET, DEL, EXISTS
Expiry EXPIRE, TTL
Counters INCR, DECR
Lists LPUSH, RPUSH, LPOP, RPOP, LLEN, LRANGE
Hashes HSET, HGET, HGETALL, HDEL
Admin KEYS, DBSIZE, FLUSHALL, SAVE, INFO

Usage

# Start the server (default: 127.0.0.1:6380)
python server.py

# Custom host/port
python server.py --host 0.0.0.0 --port 6380

# Disable persistence
python server.py --dump ""

# Connect with redis-cli
redis-cli -p 6380 PING
redis-cli -p 6380 SET name "Biswajeet" EX 3600
redis-cli -p 6380 GET name
redis-cli -p 6380 KEYS "*"

Run tests

# In one terminal
python server.py

# In another
python test_server.py

How it works

  • RESP3 protocol — the same wire format Redis uses; any Redis client connects unmodified
  • Passive expiry — keys are evicted lazily on access, O(1) per operation
  • JSON snapshotsSAVE writes an atomic snapshot; auto-save runs every 60s
  • Async TCPasyncio.start_server handles concurrent clients on a single thread
  • Zero dependencies — stdlib only (asyncio, json, fnmatch, signal)

Design decisions

Why RESP3 over a custom protocol? Compatibility — any Redis client in any language works without modification.

Why passive expiry? O(1) per access, no background scan loop. Same trade-off Redis makes.

Why JSON for persistence? Human-readable and dependency-free. A natural extension is a compact binary format (like Redis RDB) for production use.

About

Redis-protocol key-value store in Python. 25 commands, zero dependencies, async I/O.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 95.3%
  • Dockerfile 4.7%