Skip to main content

Redis queue/pool for Python

Project description

This library is set of Python and Lua scripts which enables you to easily implement queuing system based on Redis.
All the queues works well in multi-threaded environment. The only thing you have to keep in mind is that with multiple consumers the order of the items is impossible to preserve.
E.g. if multiple consumers exits unexpectedly and then you use re-enqueue method to get the items back to the queue then you will most probably lose the order of the items.
If you want to rely on the order of the items then you are required to use only one consumer at a time, reject whole batch after failure and re-enqueue everything before getting another chunk of items.
Currently, the package contains data structures called **Queue** and **Pool**.

Requirements
--------------
- Python 3.x
- Redis

Installation
--------------
`pip install py-rq`

Basic usage
--------------

Queue
---------

Use `from pyrq import Queue`.

If you need slave synchronization, use *synced_slaves_count* and *synced_slaves_timeout* arguments.

This data structure serves for managing queues of **serializable** items. Typical data flow consist of several phases:
1. Adding item (via `add_item(s)`)
2. Getting item (via `get_items`)
3. Acknowledging item (via `ack_item(s)`) when item was successfully processed **OR** rejecting item (via `reject_item(s)`) when error occurs.

**BEWARE!**. You must either acknowledge item or reject item. If you fail to do this, you have to clean internal processing queues created by **py-RQ**.

Example
-----------

```python
from pyrq import Queue

redis_client = Redis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, password=REDIS_PASSWORD, decode_responses=True)
queue = Queue(QUEUE_NAME, self.client, synced_slaves_enabled=True, synced_slaves_count=COUNT_OF_SLAVES, synced_slaves_timeout=TIMEOUT)

queue.add_item(value) # adding item

list_of_values = queue.get_items(10) # getting items
queue.ack_items(list_of_values) # acknowledging items or
queue.revert_items(list_of_values) # reverting items to the queue
```

Pool
---------

Use `from pyrq import Pool`.

If you need slave synchronization, use *synced_slaves_count* and *synced_slaves_timeout* arguments.

This data structure is designed to manage an infinite ordered set of **serializable** items. Typical data flow consist of several phases:
1. Adding item (via `add_item(s)`)
2. Getting item (via `get_items`)
3. Acknowledging item (via `ack_item(s)`) when item was successfully processed.
4. Removing item (via `remove_item(s)`) when you want to delete item from the pool

Example
-----------

```python
from pyrq import Pool

redis_client = Redis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, password=REDIS_PASSWORD, decode_responses=True)
queue = Pool(POOL_NAME, self.client, synced_slaves_enabled=True, synced_slaves_count=COUNT_OF_SLAVES, synced_slaves_timeout=TIMEOUT)

queue.add_item(value) # adding item

list_of_values = queue.get_items(10) # getting items
queue.ack_items(list_of_values) # acknowledging items
queue.remove_items(list_of_values) # removing items from the pool
```

Contributing
-----------------

Requirements:
- Python 3.x
- Virutalenv
- Redis

Building:
Just use `make`.

Test
Just use `make test`.

Project details


Download files

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

Source Distributions

py-rq.tar.gz (21.5 kB view details)

Uploaded Source

py-rq-2.0.0.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file py-rq.tar.gz.

File metadata

  • Download URL: py-rq.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py-rq.tar.gz
Algorithm Hash digest
SHA256 633ef2e642ffebc3a6914f47569d436b34418894f31dd08e9ec15b356e275072
MD5 12927762c8b8d1a65c00f114aa6f6691
BLAKE2b-256 1f9af750eb10d625133140375683d693aeeacdf558cf3090f2d13f1d3fcc603e

See more details on using hashes here.

File details

Details for the file py-rq-2.0.0.tar.gz.

File metadata

  • Download URL: py-rq-2.0.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py-rq-2.0.0.tar.gz
Algorithm Hash digest
SHA256 ed7e9f16210895417eca85a9ab82cf28d226a1d75ee7131654e35cccb630ba55
MD5 4f729b50430c46f6389e3fb9086dfd3e
BLAKE2b-256 dc66aed6e91839c8456eda16bd20fa56d69275246de34e7d8de1b67992c82a72

See more details on using hashes here.

Supported by

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