Redis Director
Do you want to distribute payloads between multiple Redis keys? Here you go!
Installation
pip install redis-director
How to Use
Publisher's Side
from redis import Redis
from redis_director import Publisher, Subscriber, generic_set_handler
pub = Publisher(
redis=Redis(),
score_key="my_stuff:my_fancy_score",
queue_key="my_stuff:my_amazing_queue",
)
def custom_handler(subscriber: Subscriber, payload):
"""
You can make custom handlers
if you have some complex stuff to do.
"""
subscriber.add_score(-2)
subscriber.redis.lpush(
"super:secret:route:hehe",
payload,
)
pub.add_subscriber(
# The subscriber's name.
"route_1",
# A generic handler.
# You can make your own if you want to.
handler=generic_set_handler(
# The subscriber's Redis key.
"route_1:queue",
# The score added to this subscriber.
# The scores are used as weights for distribution.
-1,
),
# The starting score.
default_score=100,
# The minimum score possible.
min_score=1,
# The maximum score possible.
max_score=100,
).add_subscriber(
# Make another route so
# the payloads are distributed between them.
"route_2",
handler=custom_handler,
default_score=100,
min_score=0,
max_score=1000,
)
# Fill up the publisher's queue.
pub.redis.sadd(pub.queue_key, *range(0, 1000))
# Distribute them to the subscribers!
pub.publish(100)
Subscriber's Side
You can also play with the scores from the subscriber's side!
from redis import Redis
from redis_director import Subscriber
sub = Subscriber.new(
redis=Redis(),
score_key="my_stuff:my_fancy_score",
score_member="bobs_amazing_queue",
default_score=100,
min_score=1,
max_score=100,
)
# Want to boost the chances of your subscriber to be chosen?
# Add some score!
sub.add_score(10)
# Set the score!
# This ignores the min/max score.
sub.set_score(500)
# Messed up the score?
# Just reset it back to its default score!
sub.reset_score()
Metadata
Release files for redis-director 0.7.8
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 |
|---|---|---|---|---|
| redis_director-0.7.8.tar.gz | 3.9 kB | Without provenance | Details for redis_director-0.7.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| redis_director-0.7.8-py3-none-any.whl | Python 3 | none | any | Details for redis_director-0.7.8-py3-none-any.whl |
Total release size: 9.4 kB
Release files / redis_director-0.7.8.tar.gz
| Download URL | redis_director-0.7.8.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2269048334c5a634df86e0b1a92f00239be120309f6ef2962af67d9b2a785561
|
|
BLAKE2b-256 checksum How to use checksums |
54d3ec44b7aad14b321e1aa54510edb536bb924d2ad99541bd9a36bc15d0338c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.8.10 Linux/5.15.0-119-generic
|
Release files / redis_director-0.7.8-py3-none-any.whl
| Download URL | redis_director-0.7.8-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc27743d1b26ac83e51acab34ac9e74ea40dd600e3d55e4dc2518d1b07b6dce6
|
|
BLAKE2b-256 checksum How to use checksums |
466ebc58789198cdfcd1b4001775e7a9f8f31f516ba6de6e24fc4e887e76eb34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.8.10 Linux/5.15.0-119-generic
|
Security for redis-director 0.7.8
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.