jbochi / bullock

Distributed lock for Python using Redis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bullock

A distributed lock using Redis. Inspired by Sherlock.

https://travis-ci.org/jbochi/bullock.svg?branch=master

Installation

$ pip install bullock

Usage

from bullock import Bullock
lock = Bullock(host="redis-hostname", key="my-first-lock", ttl=3600)
lock.acquire(blocking=True)
# do critical work here
lock.release()

You can also use the with statement:

from bullock import Bullock
with Bullock(host="redis-hostname", key="my-first-lock", ttl=3600):
    # do critical work here

Also supports using redis cluster:

from bullock import Bullock
lock = Bullock(host="redis-hostname", key="my-first-lock", ttl=3600, redis_cluster=True)
lock.acquire(blocking=True)
# do critical work here
lock.release()

For more examples, see tests.

About

Distributed lock for Python using Redis


Languages

Language:Python 86.4%Language:Roff 10.2%Language:Shell 3.4%