Question

How to set up django app + redis + celery

I have recently deployed a Django app. The app uses a Redis server and a celery worker to send emails and celery-beat to perform some scheduled tasks. I am unable to find a proper doc that explains how to set up redis + celery worker for a django app in digitalocean. Please explain how to do this setup


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello, I’ve been trying to sign up on the platform but it has not been working at all please how can this be rectified

Bobby Iliev
Site Moderator
Site Moderator badge
August 26, 2022

Hi there,

I could suggest starting with the following:

  • Make sure to first install Redis on your server:

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-20-04

  • Then deploy your Django app as normal:

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04

  • After that, you need to install Celery and Redis in your virtual environments:
pip install celery 
pip install redis 
  • Next, in your settings.py file add the Redis details:
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE
  • After that once your Django instance is up and running, you can also start your Celery worker, eg:
celery -A celearyapp worker -l info

For more information I could suggest the Celery official docs on how to get started with Celery and Django:

https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html#using-celery-with-django

Let me know if you have any questions!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel