Redlock+

https://img.shields.io/pypi/implementation/redlock-plus?style=flat-square https://img.shields.io/pypi/pyversions/redlock-plus?style=flat-square https://github.com/provinzkraut/redlock-plus/workflows/Tests/badge.svg

Redlock+ is an up to date, feature complete implementation of the Redlock Algorithm It’s a spiritual successor to glasslion/redlock, which is no longer maintained.

Features

  • Compliant with the standard library Lock and RLock so it can be used as a drop-in replacement

  • Complete implementation of the Redlock Algorithm

  • Autoextend functionality to make redlock safer and easier to use

  • Well tested (Python 3.6+, PyPy3)

  • Type hinted

Installation

Redlock+ is available on PyPi:

pip install redlock-plus

Basic usage

from redlock_plus import Lock

redis_instance_configs = [
    {"url": "redis://localhost/0"},
    {"url": "redis://example.com:1234/1"},
    {"url": "redis://other.host:5678/2"},
]

with Lock("my_resource", redis_instance_configs):
    # do work

or speed up things for repeated use using the factory

from redlock_plus import LockFactory

redlock_factory = LockFactory(
    [
        {"url": "redis://localhost/0"},
        {"url": "redis://localhost/1"},
        {"url": "redis://localhost/2"},
    ]
)

with redlock_factory("my_resource"):
    # do work