Skip to content

amazingchow/redlock-py

 
 

Repository files navigation

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.

Further Readings

About

Redis distributed locks in Python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Python 98.4%
  • Makefile 1.6%