Skip to main content

Redis message queue utils: a simple distributed lock based on redis, a simple message queue based on redis with ack feature.

Project description

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 lock:
        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, 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}

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redmq-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

redmq-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file redmq-0.1.0.tar.gz.

File metadata

  • Download URL: redmq-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for redmq-0.1.0.tar.gz
Algorithm Hash digest
SHA256 007bf0862497a41ffe4699f2d42ca0607ee84d0311a54622af5e7948cb568dc7
MD5 0ee017d60c4f06711e8e2f60cb7aa102
BLAKE2b-256 6a13b113c215f2e4bf4708237c09716823875320e9638d9a78ed89b9e28bf0be

See more details on using hashes here.

File details

Details for the file redmq-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: redmq-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for redmq-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee65d5d8584f475589751e98b2b1d94abeff9ad752e44e8a5190c50901b5a77e
MD5 29f1f3a5734d421b1b2899f7c8b46a2d
BLAKE2b-256 6dc09bcc4f7d4b4e5c472b0a516d5c5f4d6c380ade6c46a3ea393e9bd3e9d982

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page