Skip to main content

dbwarden-redis

Python CI

Redis-backed distributed migration locking for DBWarden.

When multiple application replicas could trigger migrations concurrently, this plugin provides a Redis-based distributed lock that ensures only one migration process runs at a time across all instances.

Installation

dbwarden plugin add dbwarden-redis

Or manually:

pip install dbwarden-redis

Usage

Async (FastAPI, etc.)

from redis.asyncio import Redis
from dbwarden_redis import migration_lock

redis = Redis.from_url("redis://localhost:6379")

async with migration_lock(redis):
    # Only one migration process runs at a time
    await run_migration()

Sync (CLI, scripts)

from redis import Redis
from dbwarden_redis import sync_migration_lock

redis = Redis.from_url("redis://localhost:6379")

with sync_migration_lock(redis):
    run_migration()

Options

async with migration_lock(
    redis,
    key="my_custom_lock",  # Redis key (default: "dbwarden_migrate")
    ttl=120,  # Lock TTL in seconds (default: 60)
):
    await run_migration()

How it works

  1. Acquire: SET key token NX EX ttl (atomic; fails if key already exists)
  2. Hold: The lock is held for the duration of the context manager
  3. Release: A Lua script deletes the key only if the current caller still owns the token (safe against TTL expiry and concurrent acquisition)

If the process crashes while holding the lock, Redis releases it automatically after the TTL expires.

Database lock vs Redis lock

Aspect Database lock (core) Redis lock (this plugin)
Scope CLI commands (migrate, rollback) Any code path you wrap
Storage dbwarden_lock table in the target database Redis key
TTL Heartbeat-based stale detection Configurable TTL (default 60s)
External dependency None (uses the database itself) Redis required
Best for Single-instance deployments Multi-instance / multi-replica deployments

Both locks can be used independently or together. The database lock protects the CLI; the Redis lock protects any entry point you wrap.

License

MIT

Release files for dbwarden-redis 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 dbwarden-redis 0.1.0
File Size Uploaded
dbwarden_redis-0.1.0.tar.gz 6.0 kB Details

Built distribution (wheel)

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

Total release size: 11.3 kB

Release files / dbwarden_redis-0.1.0.tar.gz

Download URL dbwarden_redis-0.1.0.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
62ae2772259ea93f34119cdc09de25af757df13d0be8d0c9f71daad1b93fc25d
BLAKE2b-256 checksum
How to use checksums
9746792cdd63c98aec97236271a50f8b457d73bff23db03e5c43c28ddd792e38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

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

Download URL dbwarden_redis-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e74b92a5e299a4e31ac820275411750b8d4fa6955396bfbe21744bba3b55dc26
BLAKE2b-256 checksum
How to use checksums
bec726214544c018cb9e9c5cac8bca48f8a63f3918838c32cef8b61976054aa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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