Skip to main content

A redis semaphore implementation using eval scripts

Project description

Redis Semaphore Eval

codecov Actions Status Version PyPI - Wheel Pyversions

https://redislabs.com/ebook/part-2-core-concepts/chapter-6-application-components-in-redis/6-3-counting-semaphores/

Usage

To acquire a lock:

from redis import Redis
from redis_semaphore_eval import semaphore

redis = Redis(host="localhost", port=6379, db=0)
key = "unique_lock_key"
with semaphore(redis, key=key, limit=2, expire_in=5, timeout=1) as lock_id:
    ...

To acquire a lock but continuously renew it in a background thread:

from redis import Redis
from redis_semaphore_eval import auto_renewing_semaphore

redis = Redis(host="localhost", port=6379, db=0)
key = "unique_lock_key"
with auto_renewing_semaphore(
    redis,
    key=key,
    limit=2,
    expire_in=5,
    timeout=1,
    auto_renewal_interval=4
) as lock_id:
    ...

Contributing

poetry run pre-commit install -t pre-commit -t commit-msg && poetry run pre-commit run --all
docker-compose up -d
poetry run python -m pytest
docker-compose down

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-semaphore-eval-0.3.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

redis_semaphore_eval-0.3.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file redis-semaphore-eval-0.3.0.tar.gz.

File metadata

  • Download URL: redis-semaphore-eval-0.3.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.10 Linux/5.4.0-1047-azure

File hashes

Hashes for redis-semaphore-eval-0.3.0.tar.gz
Algorithm Hash digest
SHA256 480d2348e40580d5467cb45297ccc27719ec74a8a74c80d20be55f6bd4eefd5e
MD5 5beea6ea81a9498d743ef2ce49e49e1f
BLAKE2b-256 a2d27eb2886a43f8b885fa09684160317a93f2cc58f77d792f8596671b331b45

See more details on using hashes here.

File details

Details for the file redis_semaphore_eval-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for redis_semaphore_eval-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6711d80d5a5d1f1484c7074d5259edd7dc4048701868c5eb064ec98bbda73c1
MD5 2a76fb8c44ea544848a9c8bb48658d38
BLAKE2b-256 1af386af47ba388c92ebd2c9cc3725b6820befdb8d0ff455b2227c132c9a287a

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