Skip to main content

Distributed locks with Redis

Project description

redlock-dist

Implementation of distributed locking with Redis

Distributed locks with Redis

Usage

Install:

pip install redlock-dist

example:


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')
    else:
        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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file redlock-dist-1.0.1.tar.gz.

File metadata

File hashes

Hashes for redlock-dist-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d00d3755357aac8e7256fcf9a4de004601b3b0c842cf53ed00ff8b93991d56de
MD5 04f686330809fe3b8a78290c7ff3e9e7
BLAKE2b-256 9c5088d591e2b3c03e41837633acf29a08721eecbcd464e4c56bf0cf5aeebbbe

See more details on using hashes here.

File details

Details for the file redlock_dist-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for redlock_dist-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 685e3a7b39fbf87415b21596221c21ba9aa78a4d25976fe651facc9e2e52f532
MD5 2565248e47b4e5fa0504fa23af9ed069
BLAKE2b-256 39795daa7401b8eab0e035943ff8a675fbbdad2356ae23988ea7598242952318

See more details on using hashes here.

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