redmq
Redis message queue utils: a simple distributed lock based on redis, a simple message queue based on redis with ack feature.
Install
pip install redmq
Usage Examples
redmq.lock.RedisLock
import redis
from redmq.lock import RedisLock
conn = redis.Redis()
lock_name = "test01_lock"
with RedisLock(conn, lock_name) as locked:
if locked:
pass # do things if acquired the lock
else:
pass # do things if not acquired the lock
redmq.message_queue.MessageQueue
worker.py
import time
import redis
from redmq.message_queue import MessageQueue
conn = redis.Redis()
mq = MessageQueue(conn)
while True:
task = mq.pop_nowait()
if task:
message = task["message"]
mq.acknowledge(task, result_data=message.upper())
else:
time.sleep(0.1)
client.py
import time
import redis
from redmq.message_queue import MessageQueue
conn = redis.Redis()
mq = MessageQueue(conn)
task1 = mq.push("task1")
task_info = None
for _ in range(100):
task_info = mq.get_result_nowait(task1)
if task_info:
break
time.sleep(0.1)
print(task_info["result"])
start worker
python3 worker.py
start client
python3 client.py
client output
test@test redmq % python3.9 client.py
{'error_message': 'OK', 'result_data': 'TASK1', 'success': True, 'error_code': 0}
redmq.message_queue.Consumer
consumer.py
import redis
from redmq import MessageQueue
from redmq import Consumer
def pingpong_handler(msg):
return "pong"
conn = redis.Redis("redis")
mq = MessageQueue(conn)
consumer = Consumer(mq)
consumer.register_handler("debug.pingpong", pingpong_handler)
consumer.start()
consumer.wait()
client.py
import redis
from redmq import MessageQueue
conn = redis.Redis("redis")
mq = MessageQueue(conn)
task = {
"handler": "debug.pingpong",
}
response = mq.pushwait(task)
print(response["result"])
result
test@test redmq % python3 examples/client.py
{'error_message': 'OK', 'result_data': 'pong', 'success': True, 'error_code': 0}
Why NOT using blpop instead of lpop?
We do pop_nowait via LUA script, but redis is NOT allow us to use blpop in LUA script.
Releases
v0.1.0
- First release.
v0.1.1
- redmq.message_queue.MessageQueue.push takes
high_priorityparameter. Normal message use FIFO rule, andhigh_prioritymessage use LIFO rule.
v0.2.0
- Add redmq.message_queue.Consumer, redmq.message_queue.RequestsHandler, redmq.message_queue.RequestsConsumer.
- Add redmq.schedule.Schedule and redmq.schedule.Scheduler.
- Add redmq.lock.RedisLock.renew method.
- Extend redmq.lock.RedisLock.acquire to allow the same worker acquire the same lock many times.
- Add generic async message queue handler server
requests-server.
v0.2.1
- redmq.schedule.add_runonce_task, redmq.schedule.add_crontab_task, redmq.schedule.add_interval_task add update paraemter to control if update the schedule by force or not.
- Fix redmq.schedule.add_crontab_task timezone problem.
- Fix redmq.schedule.add_interval_task rule change problem.
v0.2.2
- Doc update.
Metadata
Release files for redmq 0.2.2
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 |
|---|---|---|---|---|
| redmq-0.2.2.tar.gz | 13.2 kB | Without provenance | Details for redmq-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| redmq-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for redmq-0.2.2-py3-none-any.whl |
Total release size: 24.1 kB
Release files / redmq-0.2.2.tar.gz
| Download URL | redmq-0.2.2.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef3420170fddd8194f86edb21aa14a7b817b65860ba6653a56cfc4c35acdddd4
|
|
BLAKE2b-256 checksum How to use checksums |
65c23ef6af22c95e232713c2205253671a561fe5fb7c4c35d09be005dd52466c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Release files / redmq-0.2.2-py3-none-any.whl
| Download URL | redmq-0.2.2-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c45f3067a22aec2ce6042e662b58ca956f7c4bf0b9154698c91978128ffdb600
|
|
BLAKE2b-256 checksum How to use checksums |
c4b43b9a43577a7bab55efa15f65c1a1d3b22f294c7591b552b1bd557105d33b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Security for redmq 0.2.2
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.