分布式鎖:RedLock
RedLock 是一個使用 Python 和 Redis 實現的分布式鎖。實現了來自 @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()
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!