redis lock decorators for django
Project description
This package provides decorators that will try to acquire redis lock before calling decorated function.
Installation
pip install dumblock
Usage
Set DUMBLOCK_REDIS_URL in your django settings:
DUMBLOCK_REDIS_URL = "redis://localhost:6379"
lock_or_exit
Decorator. Before decorated function starts, try to acquire redis lock with specified key. If lock is acquired successfully, proceed executing the function. Otherwise, return immediately. The key argument can contain templated string, wich will be rendered with args and kwargs, passed to the function.
Example:
@lock_or_exit('lock_work_{}')
def workwork(x):
pass
workwork(3) # Will try to acquire redis lock 'lock_work_3'
lock_wait
Decorator. Before decorated function starts, try to acquire redis lock with specified key, waiting for waittime seconds if needed. If lock is acquired successfully, proceed executing the function. Otherwise, raise dumblock.TimeoutError. The key argument can contain templated string, wich will be rendered with args and kwargs, passed to the function.
Example:
@lock_wait('lock_work_{}', waittime=4)
def workwork(x):
pass
workwork(3) # Will try to acquire redis lock 'lock_work_3' for 4 seconds
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dumblock-0.1.tar.gz.
File metadata
- Download URL: dumblock-0.1.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a27af91b55706f54fb26036e058f3fe7fe2be3c7e882964d2ddecf14b09bda4
|
|
| MD5 |
06205206362f276d197d07861eca64cf
|
|
| BLAKE2b-256 |
30672466e7765750ba1ceae8ad270d9c41f191a36647bc685a4c6934e7d58b29
|
File details
Details for the file dumblock-0.1-py3-none-any.whl.
File metadata
- Download URL: dumblock-0.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84af2bf28140a42ffbb90fb2d64bbe8010a7c43cddefca6985c57c37facd0000
|
|
| MD5 |
4ae9c83af75dfbcf34367f8e14d43f35
|
|
| BLAKE2b-256 |
29eb63dbd66897fe184f4c83cc4f405b4380b458abe6000f766a8ab05873291d
|