Skip to content

Rq

RQ (Redis Queue) is a simple Python library for queueing jobs and processing them in the background with workers. It is backed by Redis and it is designed to have a low barrier to entry.

Check arq

Next time you are going to use this, check if arq is better.

Getting started

Assuming that a Redis server is running, define the function you want to run:

import requests

def count_words_at_url(url):
    resp = requests.get(url)
    return len(resp.text.split())

The, create a RQ queue:

from redis import Redis
from rq import Queue

q = Queue(connection=Redis())

And enqueue the function call:

from my_module import count_words_at_url
result = q.enqueue(
             count_words_at_url, 'http://nvie.com')
To start executing enqueued function calls in the background, start a worker from your project’s directory:

$ rq worker
*** Listening for work on default
Got count_words_at_url('http://nvie.com') from default
Job result = 818
*** Listening for work on default

Install

pip install rq

Reference