RedLock分布式鎖
RedLock 是一個(gè)使用 Python 和 Redis 實(shí)現(xiàn)的分布式鎖。實(shí)現(xiàn)了來(lái)自 @antirez 的 RedLock 算法。
示例代碼:
from redlock import RedLock
# By default, if no redis connection details are
# provided, RedLock uses redis://127.0.0.1:6379/0
lock = RedLock("distributed_lock")
lock.acquire()
do_something()
lock.release()
from redlock import RedLock
with RedLock("distributed_lock"):
do_something()
from redlock import RedLock
with RedLock("distributed_lock",
connection_details=[
{host='xxx.xxx.xxx.xxx', port=6379, db=0},
{host='xxx.xxx.xxx.xxx', port=6379, db=0},
{host='xxx.xxx.xxx.xxx', port=6379, db=0},
{host='xxx.xxx.xxx.xxx', port=6379, db=0},
]
):
do_something()評(píng)論
圖片
表情
