Skip to main content

Reacquiring lock for redis

Project description

Lock that prolongs itself from time to time and cancels current task if used as async context manager.

Coveralls Actions Latest Version https://img.shields.io/pypi/wheel/redis-extending-lock.svg https://img.shields.io/pypi/pyversions/redis-extending-lock.svg https://img.shields.io/pypi/l/redis-extending-lock.svg

Usage

import asyncio
import logging

from redis.asyncio import Redis
from redis_extending_lock import ExtendingLock


async def main():
    redis = Redis.from_url('redis://:hackme@localhost:6379/0')
    lock = ExtendingLock(
        redis, 'example',
        timeout=2,
        # optional, if not specified explicitly
        # would be half of timeout
        reacquiring_timeout=1,
        blocking_timeout=0,
    )

    async with lock:
        # your long-running task,
        # would be cancelled if lock would be not able to extend
        # for some reason
        await asyncio.Future()


logging.basicConfig(level=logging.DEBUG)
asyncio.run(main())

Lock can be also used without context manager:

import asyncio
import logging

from redis.asyncio import Redis
from redis_extending_lock import ExtendingLock


async def main():
    redis = Redis.from_url('redis://:hackme@localhost:6379/0')
    lock = ExtendingLock(
        redis, 'example', timeout=2, blocking_timeout=0,
    )
    await lock.acquire()
    await asyncio.sleep(5)
    await lock.release()


logging.basicConfig(level=logging.DEBUG)
asyncio.run(main())

How to develop

  • make devenv - configure the development environment

  • poetry shell or source .venv/bin/activate - activate virtualenv

  • make lint - syntax & code style check

  • make codestyle - reformat code

  • make test - test this project

  • make build - build this project

Versioning

This software follows Semantic Versioning.

Version is represented using MAJOR.MINOR.PATCH numbers, increment the:

  • MAJOR version when you make incompatible API changes

  • MINOR version when you add functionality in a backwards compatible manner

  • PATCH version when you make backwards compatible bug fixes

  • Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

In this case, the package version is assigned automatically with poem-plugins, it using on the tag in the repository as a major and minor and the counter, which takes the number of commits between tag to the head of branch.

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

redis_extending_lock-0.0.5.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

redis_extending_lock-0.0.5-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file redis_extending_lock-0.0.5.tar.gz.

File metadata

  • Download URL: redis_extending_lock-0.0.5.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.9.16 Linux/5.15.0-1034-azure

File hashes

Hashes for redis_extending_lock-0.0.5.tar.gz
Algorithm Hash digest
SHA256 78a5dfca0cd05a8b0b2c3ad762cf035dda76c8dda8531aa133dacd802413220e
MD5 0f7e06eb5596bf98be6260da947c802e
BLAKE2b-256 2af3fe535dc43db0490577dbb4d6137cd9717c070846613ef93dff0fec138297

See more details on using hashes here.

File details

Details for the file redis_extending_lock-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for redis_extending_lock-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3b8cfc722b9466cde91ba631531069a4e0afb475133191ba5a26b0be6553e039
MD5 091da6d6bcc3eedae351cff8188c1fee
BLAKE2b-256 0ff7f7932c2f77a8afd348017e96c70ed442fea74e64dc62f4edecba530221c7

See more details on using hashes here.

Supported by

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