Skip to content

About

A small Redis-backed message queue for per-user delivery and acknowledgements.

Topics

Resources

Stars

13 stars

Watchers

5 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

Repository files navigation

Simple Message Queue

A small Redis-backed message queue. Push is O(1). GET is O(N), where N is the number of messages requested. ACK is O(N), where N is the number of messages acknowledged and removed.

Compatibility

The current package metadata targets Python 2.7 and requires a running Redis server plus the redis Python package.

Usage

import redis

from simple_message_queue.message_queue import MessageQueue


user_id = 'example-user'
r = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)
queue = MessageQueue(r)

# Push messages. Each message must have a unique msg_id.
message1 = {'text': 'hello world!', 'msg_id': '2ebd68'}
message2 = {'text': 'hi world!', 'msg_id': '4dce26'}
queue.push_message(user_id, message1)
queue.push_message(user_id, message2)

# Read up to two messages for this user.
messages = queue.get_messages(user_id, 2)
# [{'text': 'hello world!', 'msg_id': '2ebd68'},
#  {'text': 'hi world!', 'msg_id': '4dce26'}]

# Acknowledge messages through position 2 when the ID at that position matches.
queue.ack_messages(user_id, 2, '4dce26')

Tests

Start Redis locally, then run:

python all_tests.py -v

About

A small Redis-backed message queue for per-user delivery and acknowledgements.

Topics

Resources

Stars

13 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages