Skip to main content

redispg

A narrow RESP2-compatible key/value server backed by PostgreSQL. See spec.md for the full specification.

Ordinary Redis clients (redis-py, redis-cli) work for the supported subset. This is a Redis-compatible PostgreSQL key/value service, not a high-performance Redis replacement.

Only RESP2 is spoken. Clients that default to RESP3 must be pinned to protocol 2, e.g. redis.Redis(..., protocol=2) with redis-py 6+ or redis-cli -2.

Supported commands

PING [message]
GET key
SET key value [EX seconds] [NX]
DEL key [key ...]
EXISTS key [key ...]
EXPIRE key seconds
TTL key
MGET key [key ...]
MSET key value [key value ...]
INCR key
DECR key
INCRBY key increment
DECRBY key decrement

Everything else is rejected with an explicit error.

Installation

python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt        # runtime only
# or, as a package with test dependencies:
pip install -e ".[test]"

Publishing to PyPI

Publishing is triggered when a GitHub release is published. Configure the repository secret PYPI_API_TOKEN with the PyPI API token (a placeholder value can be used until the real token is available), then publish a release to build and upload the package with Twine.

Running

export REDISPG_DATABASE_URL=postgresql://user:pass@localhost:5432/dbname
redispg                    # if installed with pip install -e .
# or without installing:
PYTHONPATH=src python -m redispg

The schema (src/redispg/migrations/001_init.sql) is applied automatically at startup.

Try it:

redis-cli -2 -p 6399 SET foo bar EX 60
redis-cli -2 -p 6399 GET foo
redis-cli -2 -p 6399 TTL foo

Docker

docker build -t redispg .
docker run -e REDISPG_DATABASE_URL=postgresql://user:pass@host:5432/dbname \
    -e REDISPG_HOST=0.0.0.0 -p 6399:6399 redispg

Configuration (environment variables)

Variable Default Description
REDISPG_DATABASE_URL (required) PostgreSQL DSN
REDISPG_HOST 127.0.0.1 Listen address
REDISPG_PORT 6399 Listen port
REDISPG_POOL_MIN / REDISPG_POOL_MAX 2 / 10 Connection pool bounds
REDISPG_MAX_KEY_SIZE 1024 Max key bytes
REDISPG_MAX_VALUE_SIZE 16777216 Max value bytes (16 MiB)
REDISPG_MAX_REQUEST_SIZE 17825792 Max request bytes (17 MiB)
REDISPG_MAX_ARRAY_ITEMS 10000 Max RESP array items
REDISPG_MAX_CLIENTS 1000 Max concurrent clients
REDISPG_READ_TIMEOUT 300 Idle client timeout (s)
REDISPG_COMMAND_TIMEOUT 30 Per-command timeout (s)
REDISPG_STATEMENT_TIMEOUT_MS 15000 PostgreSQL statement_timeout
REDISPG_LOCK_TIMEOUT_MS 5000 PostgreSQL lock_timeout
REDISPG_CLEANUP_INTERVAL 30 Expired-row cleanup period (s)
REDISPG_CLEANUP_BATCH_SIZE 1000 Cleanup delete batch size

Security

The service is unauthenticated. Bind it only to localhost or a trusted network. AUTH and TLS are out of scope for the MVP (see spec.md).

Tests

pip install -e ".[test]"
python -m pytest                       # protocol unit tests always run
export REDISPG_DATABASE_URL=postgresql://user:pass@localhost:5432/dbname
python -m pytest                       # + end-to-end tests against PostgreSQL

Integration tests are skipped when REDISPG_DATABASE_URL is unset or PostgreSQL is unreachable.

Layout

redispg/
├── README.md
├── spec.md
├── Dockerfile
├── requirements.txt
├── pyproject.toml
├── src/redispg/
│   ├── __main__.py     # entry point
│   ├── config.py       # env-based configuration
│   ├── protocol.py     # RESP2 parser and encoders
│   ├── commands.py     # command dispatch
│   ├── store.py        # PostgreSQL persistence
│   ├── server.py       # asyncio TCP server
│   ├── cleanup.py      # expired-row cleanup worker
│   ├── errors.py
│   └── migrations/001_init.sql
└── tests/

Metadata

Release files for redispg 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redispg 0.1.0
File Size Uploaded Provenance
redispg-0.1.0.tar.gz 16.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for redispg 0.1.0
File Interpreter ABI Platform
redispg-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.9 kB

Release files / redispg-0.1.0.tar.gz

Download URL redispg-0.1.0.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8324631eb200a8dc6181bc6f8f383ee89cd0553363c19ff41ef3de77b6980d4c
BLAKE2b-256 checksum
How to use checksums
898b28ad882e48f6703c3067c8bfd43eaf590a0b778dd17a04198715ca005064
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / redispg-0.1.0-py3-none-any.whl

Download URL redispg-0.1.0-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33b3eb1c8e4bc34248878ce2cac7a0b5bcc4aff7704e3cc38cec2aa75af5bf12
BLAKE2b-256 checksum
How to use checksums
7e2fdae773911c835153d0164eedb5df1fdef2b8cb6cc2ebb2145277558e5149
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for redispg 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page