Skip to main content

Distributed locks with Redis

Project description


Implementation of distributed locking with Redis

Distributed locks with Redis



pip install redlock-dist


from redis import StrictRedis
from redlock_dist import RedLock

rds = StrictRedis(host='localhost', port=6379, db=0)

:param expire: lock key ttl(ms)
:param retry_times: retry times to get lock
:param retry_interval: retry interval(ms)
with RedLock(rds, 'key-name', expires=30000, retry_times=3, retry_interval=50) as red_lock:

    if red_lock:
        print('get lock')
        print('do not get lock')

Principle and notes

Because Redis is single-threaded and you can use SET key value NX PX expires

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

redlock-dist-1.0.1.tar.gz (2.1 kB view hashes)

Uploaded source

Built Distribution

redlock_dist-1.0.1-py3-none-any.whl (2.6 kB view hashes)

Uploaded py3

Supported by

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