aioredlock-py
Secure and efficient distributed locks (Redisson like) implemetation. Ensure efficient performance with biased locking's implementation, can load more than 1k/s of concurrent requests with default parameter settings.
Requirements
- aioredis>=2.0.0
Install
pip install aioredlock-py
Feature
- Ensure reliability with context manager.
- Use lua scripts to ensure atomicity on lock release.
- Notification prompt you to cancel the following execution if acquisition fails
- Reliable in high concurrency.
Documentation
https://aioredlock-py.readthedocs.io
Basic usage
import asyncio
import aioredis
from aioredlock_py import Redisson
async def single_thread(redis):
for _ in range(10):
async with Redisson(redis, key="no1") as lock:
if not lock:
# If the lock still fails after several attempts, `__aenter__`
# will return None to prompt you to cancel the following execution
return 'Do something, failed to acquire lock' # raise ...
# else
# Service logic protected by Redisson
await redis.incr("foo")
async def test_long_term_occupancy(redis):
async with Redisson(redis, key="no1", ex=10) as lock:
if not lock: return;
# Service logic protected by Redisson
await redis.set("foo", 0)
# By default, a lock is automatically released if no action is
# taken for 20 seconds after redisson holds it. Let's assume that
# your service logic takes a long time (30s in this case) to process,
# you don't need to worry about it causing chaos, because there's
# background threads help you automatically renew legally held locks.
await asyncio.sleep(30)
await redis.incr("foo")
async def main():
redis = aioredis.from_url("redis://localhost")
await redis.delete("redisson:no1")
await redis.set("foo", 0)
await asyncio.gather(*(single_thread(redis) for _ in range(20)))
assert int(await redis.get("foo")) == 200
# test_long_term_occupancy(redis)
asyncio.run(main())
Metadata
Release files for aioredlock-py 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aioredlock_py-0.1.5.tar.gz | 6.0 kB | Without provenance | Details for aioredlock_py-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aioredlock_py-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for aioredlock_py-0.1.5-py3-none-any.whl |
Total release size: 12.5 kB
Release files / aioredlock_py-0.1.5.tar.gz
| Download URL | aioredlock_py-0.1.5.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd56ef89fd9d6b82916ceb9404cd2bd050610e37fe3cc59611a5582982f01028
|
|
BLAKE2b-256 checksum How to use checksums |
6f13547bbf3253de66806ec2f5309294dfcb43753b5bd9b686151757e6e68f7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.12
|
Release files / aioredlock_py-0.1.5-py3-none-any.whl
| Download URL | aioredlock_py-0.1.5-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3e3b6448eb79b0d181b41df66f826fa54d4fa9986f4dc2a26ccdf135f8b95b44
|
|
BLAKE2b-256 checksum How to use checksums |
6c2452daa6e1bc8c3045876d22f476dd5e5736a01d7b23073081104fc6649ac9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.12
|
Security for aioredlock-py 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.