Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Install Redis as Your Broker

00:00 Installing Redis. You need a message broker so that Celery can communicate with the task producer. You’ll use Redis because it can serve both as a message broker and a database backend.

00:12 At the same time, head back to your terminal and install Redis on your system. If you’re using Linux, then these are the commands that you’ll need

00:49 on macOS. The installation requires Homebrew to be installed if you are not familiar with it. Homebrew is a package manager, which will allow you to install a wide range of packages with much less effort than installing or compiling from source.

01:11 After the installation is complete, you can start the Redis server. To confirm that everything worked. Open up a new terminal window and start the server.

01:25 This window will be your dedicated terminal window for Redis, so keep it open. For the rest of the course running Redis Server starts. The Redis server you’ll run.

01:35 Redis is a process that’s independent of Python, so you don’t need to have your virtual environment activated when you start it. After running Redis server, your terminal will show the Redis logo as ASCII Art, along with a few startup log messages.

01:49 The most recent log message will tell you that Redis is ready to accept connections. To test this, start the Redis CLI in another new terminal window.

02:02 Once the prompt has changed, you can type ping and press enter and then wait for the answer from Redis. It should respond with an authoritative PONG.

02:12 If you got this response, then your Redis installation was successful and Celery will be able to communicate with it. Quit the Redis CLI by pressing control C before moving to the next step.

02:25 You’ll need a Python client to interface with Redis. Confirm that you’re in a terminal window where your virtual environment is still active,

02:35 and then install redis-py.

02:44 This command doesn’t install Redis on your system, but provides a Python interface for connecting to it. You’ll need to install both Redis on your system and redis-py in your Python virtual environment to allow you to work with Redis in Python.

03:01 After completing both installations, you’ve successfully set up the message broker, however, you haven’t yet connected your producer to Celery. If you tried to start Celery now and include the producer app name by passing the -A option together with the name of the Django app, you’ll run into yet another error.

03:28 So far, the distributed task queue can’t receive messages from the Django application because there’s no Celery app set up within the Django project. But in the next section of the course, you’ll add the necessary code to the Django app so it can serve as a task producer for Celery.

Become a Member to join the conversation.