A thin convenience wrapper around redis-py for storing Python values (via pickle), working with Redis hashes, performing atomic updates, and managing distributed locking primitives.
Installation
pip install dkredis
Usage
Connecting
from dkredis import dkredis
r = dkredis.connect()
connect() reads REDIS_HOST and REDIS_PASSWORD from environment variables, defaulting to localhost:6379.
Storing Python values
Any pickleable value can be stored and retrieved:
from dkredis.dkredis import set_pyval, get_pyval, pop_pyval
set_pyval('mykey', {'answer': 42}, secs=300) # expires in 5 minutes
get_pyval('mykey') # {'answer': 42}
pop_pyval('mykey') # {'answer': 42}, then deletes the key
Dict / hash operations
Store and retrieve dicts as Redis hashes (string values only):
from dkredis.dkredis import set_dict, get_dict
set_dict('user:1', {'name': 'Alice', 'role': 'admin'}, secs=600)
get_dict('user:1') # {'name': 'Alice', 'role': 'admin'}
Atomic updates
update() uses WATCH/MULTI pipelines for optimistic locking:
from dkredis.dkredis import update, setmax, setmin
r.set('counter', 40)
update('counter', lambda val: val + 2) # atomically set to 42
setmax('highscore', b'100') # r[key] := max(r[key], val)
setmin('lowscore', b'5') # r[key] := min(r[key], val)
remove_if() atomically deletes a key only if it holds an expected value (implemented via a Lua script):
from dkredis.dkredis import remove_if
remove_if('mykey', expected_value)
Locking primitives
fetch_lock – prevents thundering-herd on cache misses. Only one process fetches fresh data; others receive False and should fall back to stale cache:
from dkredis.dkredislocks import fetch_lock
with fetch_lock('weatherapi', timeout=10) as should_fetch:
if should_fetch:
data = call_external_api()
cache.set('weather', data, 60)
else:
time.sleep(1)
data = cache.get('weather')
rate_limiting_lock – sets multiple keys atomically with MSETNX to enforce a per-resource cooldown period:
from dkredis.dkredislocks import rate_limiting_lock
if rate_limiting_lock(['smtp.example.com'], seconds=15):
send_email()
mutex – a polling mutex using SETNX with expiry-based recovery:
from dkredis.dkredislocks import mutex
with mutex('mylock', seconds=30, timeout=60):
# mutual exclusion zone
...
Multi-hash field lookup
mhkeyget() fetches one field from all hashes matching a key pattern:
from dkredis.dkredis import mhkeyget
mhkeyget('lock.*', 'x')
# {'lock.a': '1', 'lock.b': '2', 'lock.c': '3'}
Requirements
Python 3
redis==5.0.1
A running Redis server (localhost:6379 by default)
Metadata
Release files for dkredis 1.0.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 |
|---|---|---|---|---|
| dkredis-1.0.5.tar.gz | 14.6 kB | Without provenance | Details for dkredis-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dkredis-1.0.5-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for dkredis-1.0.5-py2.py3-none-any.whl |
Total release size: 26.4 kB
Release files / dkredis-1.0.5.tar.gz
| Download URL | dkredis-1.0.5.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c66b3dc205c5188b71fb87ebca8213b2a92aab6d885bc1f223a06501b513214
|
|
BLAKE2b-256 checksum How to use checksums |
c583a00b76eacb4272dd56072ac10598969686063542ebfc6902c26780b4710e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.16
|
Release files / dkredis-1.0.5-py2.py3-none-any.whl
| Download URL | dkredis-1.0.5-py2.py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a62748709080fe15cab29de3462fd900d2d3418243ff3431e9900dfc0085da11
|
|
BLAKE2b-256 checksum How to use checksums |
bbb146b64b40b2782a3ae4b013da1798cb0275681b1b57f7f0c2248f6f265235
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.16
|
Security for dkredis 1.0.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.