🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

redis-semaphore-eval

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-semaphore-eval

A redis semaphore implementation using eval scripts

0.3.0
100

Supply Chain Security

100

Vulnerability

98

Quality

100

Maintenance

100

License

Maintainers
1

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

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts