Lock context manager implemented via redis SETNX/BLPOP.
Project description
Lock context manager implemented via redis SETNX/BLPOP.
Interface targeted to be exactly like threading.Lock.
Usage
Because we don’t want to require users to share the lock instance across processes you will have to give them names. Eg:
conn = StrictRedis()
with redis_lock.Lock(conn, "name-of-the-lock"):
print("Got the lock. Doing some work ...")
time.sleep(5)
Eg:
lock = redis_lock.Lock(conn, "name-of-the-lock")
if lock.acquire(blocking=False):
print("Got the lock.")
else:
print("Someone else has the lock.")
Features
based on the standard SETNX recipe
optional expiry
no spinloops at acquire
Implementation
redis_lock will use 2 keys for each lock named <name>:
lock:<name> - a string value for the actual lock
lock-signal:<name> - a list value for signaling the waiters when the lock is released
This is how it works:
TODO
???
Requirements
Redis 2.6 or later.
Python 2.6, 2.7, 3.2, 3.3 and PyPy are supported.
Similar projects
bbangert/retools - acquire does spinloop
distributing-locking-python-and-redis - acquire does polling
cezarsa/redis_lock - acquire does not block
andymccurdy/redis-py - acquire does spinloop
mpessas/python-redis-lock - blocks fine but no expiration
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file python-redis-lock-0.0.1.tar.gz.
File metadata
- Download URL: python-redis-lock-0.0.1.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29dfb74efc78aed46dc7df29a3c0621f03f8ac793033a336b9622446f6823c14
|
|
| MD5 |
a21cc2b48ef931670470fda7db471eda
|
|
| BLAKE2b-256 |
805f3a6e66ad7af458e531bf7243518af2dc1a006eebc8c38a8ce3eebf6911dc
|