SlideShare a Scribd company logo
Task queuing with
Redis and rq
Nadja Deininger
Who am I?
Python developer
Software engineer at Beautifeye
@machine_lady
Why use queues?
- Execute long tasks asynchronously
- Parallelise work
- Distribute work
Queues in Python
- Celery
- RabbitMQ
- Surely, many more…
- rq
Redis
redis.io
Key-value store
Supports lists (and other data structures)
Can be used to host queues
rq
python-rq.org
Needs a running Redis server - and that’s it!
Getting started
import rq
from redis import Redis
from my_module import my_function
with rq.Connection(Redis()):
q = rq.Queue("my_queue")
job = q.enqueue(my_function,
args=("arg1", "arg2"))
Performing work
rq comes with a default worker script:
$ rqworker queue1 queue2
Picks up jobs from the first nonempty queue.
Customise worker behaviour
Write your own worker class to e.g.
- manage a database connection
- avoid using os.fork
and use it by specifying
$ rqworker -w ‘path.to.MyWorker’
Get job results
Return value of enqueued function (if any) can
be accessed through job.result
Results are stored under job’s Redis hash
- default TTL: 500s
- job.result will be None until task is done
Dealing with failure
By default: put a job onto the failed queue;
can be accessed through rq.FailedQueue
Failed jobs don’t expire.
They can be retried (usually manually).
Dealing with failure differently
Supply your own exception handler to a Worker
instance:
worker = rq.Worker(queues,
exc_handler=my_exception_handler)
Monitoring rq - command line
rq-dashboard - web monitoring tool
rq-dashboard - web monitoring tool
Lessons learned
- Module imports can impact performance
- Don’t let queues get too large
- Functions cannot depend on context
Questions?
Nadja Deininger
nadja@ef.gy
@machine_lady

More Related Content

What's hot (20)

PDF
Ractor's speed is not light-speed
SATOSHI TAGOMORI
 
PDF
[231] the simplicity of cluster apps with circuit
NAVER D2
 
ODP
Rex - Lightning Talk yapc.eu 2013
Jan Gehring
 
PDF
OHHttpStubs
CocoaHeads France
 
PPTX
Async and Await on the Server
Doug Jones
 
PPTX
Rsyslog version naming (v8.6.0+)
Rainer Gerhards
 
PPTX
Scalable Web Apps
Piotr Pelczar
 
PDF
High Performance Systems in Go - GopherCon 2014
Derek Collison
 
PDF
Coscup 2013 : Continuous Integration on top of hadoop
Wisely chen
 
PDF
Writing Rust Command Line Applications
All Things Open
 
PDF
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Vaclav Tunka
 
PPTX
Async Programming in C# 5
Pratik Khasnabis
 
KEY
About Clack
fukamachi
 
KEY
Writing Better Haskell
nkpart
 
PDF
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Codemotion
 
PPTX
End to-end async and await
vfabro
 
PDF
NSLogger network logging extension
CocoaHeads France
 
PDF
All of the thing about Postman
Alihossein shahabi
 
PDF
LCE13: Test and Validation Summit: Evolution of Testing in Linaro (I)
Linaro
 
PDF
Efficient HTTP applications on the JVM with Ratpack - Voxxed Days Berlin 2016
Alvaro Sanchez-Mariscal
 
Ractor's speed is not light-speed
SATOSHI TAGOMORI
 
[231] the simplicity of cluster apps with circuit
NAVER D2
 
Rex - Lightning Talk yapc.eu 2013
Jan Gehring
 
OHHttpStubs
CocoaHeads France
 
Async and Await on the Server
Doug Jones
 
Rsyslog version naming (v8.6.0+)
Rainer Gerhards
 
Scalable Web Apps
Piotr Pelczar
 
High Performance Systems in Go - GopherCon 2014
Derek Collison
 
Coscup 2013 : Continuous Integration on top of hadoop
Wisely chen
 
Writing Rust Command Line Applications
All Things Open
 
Jenkins-Koji plugin presentation on Python & Ruby devel group @ Brno
Vaclav Tunka
 
Async Programming in C# 5
Pratik Khasnabis
 
About Clack
fukamachi
 
Writing Better Haskell
nkpart
 
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Codemotion
 
End to-end async and await
vfabro
 
NSLogger network logging extension
CocoaHeads France
 
All of the thing about Postman
Alihossein shahabi
 
LCE13: Test and Validation Summit: Evolution of Testing in Linaro (I)
Linaro
 
Efficient HTTP applications on the JVM with Ratpack - Voxxed Days Berlin 2016
Alvaro Sanchez-Mariscal
 

Recently uploaded (20)

PPTX
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
PDF
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
NPD Software -Omnex systems
omnex systems
 
PPTX
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Library_Management_System_PPT111111.pptx
nmtnissancrm
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
PDF
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
PPTX
Prompt Like a Pro. Leveraging Salesforce Data to Power AI Workflows.pptx
Dele Amefo
 
PDF
Why is partnering with a SaaS development company crucial for enterprise succ...
Nextbrain Technologies
 
PDF
Best Web development company in india 2025
Greenusys
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
NPD Software -Omnex systems
omnex systems
 
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Library_Management_System_PPT111111.pptx
nmtnissancrm
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
Prompt Like a Pro. Leveraging Salesforce Data to Power AI Workflows.pptx
Dele Amefo
 
Why is partnering with a SaaS development company crucial for enterprise succ...
Nextbrain Technologies
 
Best Web development company in india 2025
Greenusys
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Ad

Task queuing with redis and rq

Editor's Notes

  • #4: Execute long tasks: Example e.g. snapshot Parallelise work: just start 1 worker/core Distribute work: workers on >1 machines
  • #7: Note: Mention that it does not work on WIndows!