Skip to main content

Redis Distributed Lock

Redis distributed lock for python3, using setnx and lua script, provide block and no-block function

Install

pip install redis-distributed-lock

Usage

from redis_distributed_lock import RDLock
import redis

redisconn = redis.Redis(host="127.0.0.1", port=6379, decode_responses=True)
lock = RDLock(redisconn)

# Prevent CPU consumption all the time, 
# specify the sleeptime for block mode (default 100 millsec)
lock = RDLock(redisconn, sleeptime=1000)

# Specify lock prefix name (default: lock_)
lock = RDLock(redisconn, prefix="lock_")

# Using block method, default timeout is 0 (second)
# default key expire is 5000 millsec
key = "key"
try:
    if lock.acquire(key, expire=3000, timeout=2):
        # Do something
        pass
finally:
    lock.release(key)

# Using No-block method
lock.acquire_no_block(key)

Release files for redis-distributed-lock 1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redis-distributed-lock 1.3
File Size Uploaded
redis_distributed_lock-1.3.tar.gz 2.1 kB Details

Release files / redis_distributed_lock-1.3.tar.gz

Download URL redis_distributed_lock-1.3.tar.gz
Size 2.1 kB
Tags Source
SHA-256 checksum
How to use checksums
75ef6c500ec3a29c948979220ff5f062e43683a317afb8e0d09a57b66ee267fd
BLAKE2b-256 checksum
How to use checksums
6f9186669b22a5b162f880902ad45736a13bd73b5d85118410ae707e409e4de2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

1.3 This release

1 release file

1.2

1 release file

1.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page