0
0
Fork
You've already forked RedPy
0
Page: Home
15 Home
XADE edited this page 2025年07月29日 16:39:01 +02:00

RedPy

A lightweight, asynchronous Redis-compatible server built using asyncio, capable of handling common Redis commands, basic replication, and streaming support. The implementation is fully self-contained with no third-party dependencies, using only Python’s standard library.

Mirror: GitHub

Server

Installing the server:

pip install git+https://codeberg.org/zz/RedPy

Starting the server

redpy [--dir DIR] [--dbfilename FILE] [--port PORT] [--replicaof "HOST PORT"]
Option Description Default
--dir Directory to store/load the RDB file .
--dbfilename Name of the database file dump.rdb
--port Port to listen on 6379
--replicaof "HOST PORT" Start as a replica of another instance None

Example

Start a master server on default port 6379:

redpy

Start a replica on port 6380, syncing from the above:

redpy --port 6380 --replicaof "127.0.0.1 6379"

Executing commands

  • We'll use redis-cli to connect as a client and execute commands.

  • With Docker,

 docker run -it --network="host" redis redis-cli -h 127.0.0.1 -p 6379 set key value
  • Without Docker, instructions to install and use redis-cli can be found here.

Features

Feature Description
In-memory DB Extremely fast data access
Redis protocol Full support for RESP (REdis Serialization Protocol)
Master-replica Asynchronous replication via PSYNC, REPLCONF, and WAIT
Expiry Optional key expiration via SET key value PX ms
Simple persistence Supports loading a hex-encoded RDB snapshot on startup
No dependencies Built only on Python’s standard library for maximum portability

Supported Commands

Command Description
PING, ECHO <msg> Health check, echo
SET, GET, DEL Basic key-value ops with optional expiration
INCR Atomic integer increment
CONFIG GET, KEYS * Config view, list keys
TYPE, INFO Key type, server info
XADD, XREAD, XRANGE Stream support
LPUSH, RPUSH, LPOP, LRANGE, LLEN, BLPOP List support
MULTI, EXEC, DISCARD Transactions
WAIT, PSYNC, REPLCONF Replication commands

Implementing Load Balancing

to be added

Limitations

  • This is not a full Redis replacement, only selected commands are implemented
  • Persistence is one-way (load only), no automatic writes to RDB
  • Minimal error checking and no password/auth support
  • No way to recover incase of complete power failure, i.e. all servers including replicas are stopped

License

MIT License