qx-cache
Redis client, Lua-atomic idempotency store, and distributed lock for the Qx framework.
What lives here
qx.cache.Cache— thin async Redis client wrapper with typedget/set/delete/existsmethods and TTL support.qx.cache.CacheSettings— Pydantic settings for Redis connection URL.qx.cache.create_client— async factory that opens and validates a Redis connection.qx.cache.IdempotencyStore— Lua-script-based atomic check-and-set. A single round-trip to Redis either claims an idempotency key (first caller wins) or returns the cached result (all subsequent callers). Used byIdempotencyBehaviorin the Mediator pipeline to make command handlers idempotent.qx.cache.DistributedLock— Redis-backed advisory lock with TTL and async context-manager interface. UsesSET NX PXfor acquisition and Lua for safe release (only the holder can release).qx.cache.LockNotHeldError— raised when attempting to release a lock that has expired or was never acquired.
Usage
Idempotency store
from qx.cache import IdempotencyStore, create_client
redis = await create_client(settings.cache.url)
store = IdempotencyStore(redis, ttl_seconds=3600)
# In a command handler or pipeline behavior:
key = f"create-order:{cmd.idempotency_key}"
cached = await store.get(key)
if cached is not None:
return Result.success(cached)
result = await do_work(cmd)
if result.is_success:
await store.set(key, result.value)
return result
Distributed lock
from qx.cache import DistributedLock
async with DistributedLock(redis, "outbox-relay-leader", ttl_seconds=30):
await relay.run_once()
Design rules
- Lua atomicity —
IdempotencyStoreuses a single Lua script for the check-and-set so there is no window between checking and setting, even under concurrent requests. - No silent failures —
DistributedLockraisesLockNotHeldErrorif the lock has expired before you release it, so callers know their critical section may have overlapped. - The cache layer has no dependency on
qx-dborqx-cqrs. It can be used standalone.
Metadata
Release files for qx-cache 1.1.0
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 |
|---|---|---|---|---|
| qx_cache-1.1.0.tar.gz | 6.2 kB | Without provenance | Details for qx_cache-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qx_cache-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for qx_cache-1.1.0-py3-none-any.whl |
Total release size: 13.9 kB
Release files / qx_cache-1.1.0.tar.gz
| Download URL | qx_cache-1.1.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0189bead001de290b860a64deca46de698b6189386f93ef57f0e1b988f4d684b
|
|
BLAKE2b-256 checksum How to use checksums |
543fdd0389d703cda5d4e4b380e996bf20f3d071403fdac82686f82b99b726a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / qx_cache-1.1.0-py3-none-any.whl
| Download URL | qx_cache-1.1.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9486791ca377d8a029bbb1106b9095a4e6ffa2cf8df07a9f6ee5a6ee4ac79bd1
|
|
BLAKE2b-256 checksum How to use checksums |
5164808c8c89f99fd57880663c6f378109150651ee6634d1e1ae4f0cd49b1b1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for qx-cache 1.1.0
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.