Skip to main content

A Redis distributed lock implementation in Python

Project description

pyredlock - A Redis distributed lock implementation in Python

This python lib implements the Redis-based distributed lock manager algorithm described in this blog post.

How to use it?

To create a lock manager:

from pyredlock import RedisClient
from pyredlock import Redlock, Lock

...
client = RedisClient(client_conf={
    "endpoint": "localhost:6379",
    "password": "your_redis_password",
    "db": 0,
    "socket_timeout": 0.5,
    "socket_connect_timeout": 0.25
})
lock_mgr = Redlock(connections=[client.get_connection()], async_mode=False)
...

To acquire a lock:

...
success, my_lock = lock_mgr.lock("my_resource_name", 1000)
...

To release a lock:

...
lock_mgr.unlock(my_lock)
...

To extend your ownership of a lock that you already own:

...
lock_mgr.extend(my_lock, 1000)
...

Disclaimer: This implementation is currently a proposal, it was not formally analyzed. Make sure to understand how it works before using it in your production environments.

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

pyredlock-1.0.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyredlock-1.0.0-py2.py3-none-any.whl (10.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pyredlock-1.0.0.tar.gz.

File metadata

  • Download URL: pyredlock-1.0.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for pyredlock-1.0.0.tar.gz
Algorithm Hash digest
SHA256 89e6255f4cadd4f2288e177415adbb07147aec971a36d5ef3c516c3923c047b3
MD5 fa1f5f7423d8500db3b49baa74c91886
BLAKE2b-256 31679a227e4ade8acf07c87c5ef028acfd75e7fa20bc9d87fa1a6638f4356cba

See more details on using hashes here.

File details

Details for the file pyredlock-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pyredlock-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for pyredlock-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5642227d97d9d8a8c0adb598662ea867e9dd64f49ac5c7aef709d554e436363d
MD5 6ca06814c7c111fa90c8a49decba0930
BLAKE2b-256 6c23826dac893e6942456ff1480ed4d5da6b1da4a6d119116ea562b3ef6ce969

See more details on using hashes here.

Supported by

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