Skip to main content

A cluster-supported distributed lock on Redis and Python

Project description

Redistock

A simple and easy-to-use and cluster-supported distributed lock implement based on Redis and Python.

Installation

pip install redistock

Usage

Simple usage:

import redis
from redistock import Redistock

redis_conn = redis.StrictRedis(...)

# simple
lock = Redistock(redis_conn, 'name')
if lock.acquire():
    print('Obtained lock')
lock.release()

# with statement
with Redistock(redis_conn, 'name'):
    print('Obtained lock')

Advanced usage:

import redis
from redistock import Redistock
from redistock import RedistockNotObtained

redis_conn = redis.StrictRedis(...)


with Redistock(redis_conn, 'name', ttl=1):
    # will be blocked for 1 seconds
    print('Obtained lock')


with Redistock(redis_conn, 'name', ttl=0.001):
    # will be blocked for 1 milliseconds
    print('Obtained lock')


with Redistock(redis_conn, 'name', delay=1):
    # will delay 1 seconds between twice retry, default 0.001
    print('Obtained lock')


lock = Redistock(redis_conn, 'name', block=False)
# do not retry, raise RedistockNotObtained if not obtained lock
if lock.acquire():
    print('Obtained lock')
lock.release()


try:
    with Redistock(redis_conn, 'name', timeout=10):
        # will try to acquire for 10 seconds, success or raise RedistockNotObtained
        # after 10 seconds
        print('Obtained lock')
except RedistockNotObtained:
    print('Not obtained lock')

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

redistock-0.1.3.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redistock-0.1.3-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file redistock-0.1.3.tar.gz.

File metadata

  • Download URL: redistock-0.1.3.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.9

File hashes

Hashes for redistock-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6c3c3931d05dd89db9ddfb9595c25785f493ae9c45cc733f8a931923c00ed3ef
MD5 8a42728f8bf35528b115d92f4282cd2c
BLAKE2b-256 8c73619c267ec96b67639f8b1cf263d28d99c4561eb5b6d3cb2d7628142b8692

See more details on using hashes here.

File details

Details for the file redistock-0.1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: redistock-0.1.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.9

File hashes

Hashes for redistock-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9f3691687afd1b7ecbaebb324d1423a9bd5de428ccbf9b6acb24595bc32bfbd1
MD5 5aae82aa182e13626fc8581df0eb4457
BLAKE2b-256 4a524601168344854bc88b8e4a4b1c03ac9bac2bcdc60f5508b163f2d397b8d7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page