Skip to main content

Distributed locks with Redis

Project description

.. figure:: https://github.com/glasslion/redlock/raw/master/docs/assets/redlock-small.png
:alt: RedLock logo

RedLock logo
RedLock - Distributed locks with Redis and Python
-------------------------------------------------

|Build Status|

This library implements the RedLock algorithm introduced by
[@antirez](http://antirez.com/)

The detailed description of the RedLock algorithm can be found in the
Redis documentation: `Distributed locks with
Redis <http://redis.io/topics/distlock>`__.

The ``redlock.RedLock`` class shares a similar API with the
``threading.Lock`` class in the Python Standard Library.

Simple Usage
~~~~~~~~~~~~

.. code:: python

from redlock import RedLock
lock = RedLock("distributed_lock")
lock.acquire()
do_something()
lock.release()

With Statement / Context Manager
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As with ``threading.Lock``, ``redlock.RedLock`` objects are context
managers thus support the `With
Statement <https://docs.python.org/2/reference/datamodel.html#context-managers>`__.
Thsi way is more pythonic and recommended.

.. code:: python

from redlock import RedLock
with RedLock("distributed_lock"):
do_something()

.. |Build Status| image:: https://travis-ci.org/glasslion/redlock.svg?branch=master
:target: https://travis-ci.org/glasslion/redlock

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redlock-0.1.3.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

redlock-0.1.3-py2-none-any.whl (4.7 kB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page