Skip to main content

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

This version

0.1

Download files

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

Files for dumblock, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size dumblock-0.1-py3-none-any.whl (4.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size dumblock-0.1.tar.gz (2.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page