Distributed locks with Redis
Project description
redlock-dist
Implementation of distributed locking 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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for redlock_dist-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 685e3a7b39fbf87415b21596221c21ba9aa78a4d25976fe651facc9e2e52f532 |
|
MD5 | 2565248e47b4e5fa0504fa23af9ed069 |
|
BLAKE2b-256 | 39795daa7401b8eab0e035943ff8a675fbbdad2356ae23988ea7598242952318 |