Greg Thatcher
Greg Thatcher

Reputation: 1443

How to setup Celery to talk ssl to Azure Redis Instance

Using the great answer to "How to configure celery-redis in django project on microsoft azure?", I can configure Celery to use Azure Redis Cache using the non-ssl port, 6379, using the following Python code:

from celery import Celery
# This one works
url = 'redis://:<access key>@<my server>.redis.cache.windows.net:6379/0'
# I want to use a url that specifies ssl like one of the following:
# url = 'redis://:<my key>=@<my server>.redis.cache.windows.net:6380/0'
# url = 'redis://:<my key>@<my server>.redis.cache.windows.net:6380/0?ssl=True'
app = Celery('tasks', broker=url)

@app.task
def add(x, y):
    return x + y

However, I would like to have celery use ssl and communicate on port 3380 using ssl to the Azure Redis Cache. If I change the port to 6380, I get an "Error while reading from socket" after a few minutes of waiting after running the following command:

celery -A tasks worker --loglevel=INFO -Q "celery" -Ofair

Does anyone know how to configure this, on the Celery or Azure side, so that I can have celery communicate on the default 3380 port on Azure Redis Cache using ssl?

I am using the latest version of Celery (4.0.2)

Note that code like the following works with no problem when connecting directly from a Linux client (on Azure) using port 3380 and ssl using Python's redis library:

import redis
redis.StrictRedis(host='<my host>.redis.cache.windows.net', port=6380, db=0, password='<my key>', ssl=True)

Upvotes: 8

Views: 9930

Answers (2)

Daniel Delgado
Daniel Delgado

Reputation: 5333

It's already possible using rediss:// instead redis://.

url = 'rediss://:<access key>@<my server>.redis.cache.windows.net:6380/0'

Upvotes: 13

Todd Schiller
Todd Schiller

Reputation: 486

For the broker, you should be able to set the broker_use_ssl configuration option.

For the backend, the option redis_backend_use_ssl was made available in the 4.1.0 release.

The ability to enable SSL via the URL isn't available yet: https://github.com/celery/celery/issues/2833

Also, note that official support for Windows was dropped in 4.0. However, you might be able to get it working by following the instructions at https://github.com/celery/celery/issues/4082

Upvotes: 4

Related Questions