Sitemap

Redis Queue implementation in Python

2 min readAug 31, 2019

--

RQ (Redis Queue) is a simple Python library for queueing jobs and processing them in the background with workers.

RQ (Redis Queue) is a simple Python library for queueing jobs and processing them in the background with workers.

After redis installation, run the redis server with the command,

➜ redis-server

Use the below code in the mentioned files,

Get Vigneshwar Ravichandran’s stories in your inbox

Join Medium for free to get updates from this writer.

app.py

from redis import Redis
from rq import Queue
from my_module import count_words_at_url
q = Queue(connection=Redis())result = q.enqueue(count_words_at_url, 'http://nvie.com')

my_module.py

import requestsdef count_words_at_https://medium.com/url(url):
resp = requests.get(url)
return len(resp.text.split())

Pip install the below modules

➜ pip install rq

➜ pip install requests

The worker:

To start executing enqueued function calls in the background, start a worker from your project’s directory:

➜ rq worker

Press enter or click to view image in full size

Run the python file app.py and check the rq worker terminal for the job updation.

Press enter or click to view image in full size

For any queries ping me at https://twitter.com/vigneshwar1998

--

--