Skip to main content

Redis distributed lock for python

Project description

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)

Project details


Download files

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

Source Distribution

redis_distributed_lock-1.3.tar.gz (2.1 kB view details)

Uploaded Source

File details

Details for the file redis_distributed_lock-1.3.tar.gz.

File metadata

  • Download URL: redis_distributed_lock-1.3.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for redis_distributed_lock-1.3.tar.gz
Algorithm Hash digest
SHA256 75ef6c500ec3a29c948979220ff5f062e43683a317afb8e0d09a57b66ee267fd
MD5 768b6d26afc1d1a1b2615ba241e88e27
BLAKE2b-256 6f9186669b22a5b162f880902ad45736a13bd73b5d85118410ae707e409e4de2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page