title: How to securely connect to Azure redis from celery-django project?
body: <p>I am trying to convert from a local Redis container to a managed service in Azure.</p>
  <p>I know I have the correct server name and key because</p>
  <pre><code>redis-cli -h &lt;server-name&gt;.redis.cache.windows.net -p 6379 -a &lt;azure_key&gt;
  </code></pre>
  <p>connects.</p>
  <p>Locally my connection before  in celery_manager.py was</p>
  <pre><code>app = Celery(broker=redis://redis:6379)
  </code></pre>
  <p>I updated broker successfully with the non-ssl port enabled.</p>
  <pre><code>broker=redis://:&lt;key&gt;@&lt;server-name&gt;.redis.cache.windows.net:6379 per [this question]
  </code></pre>
  <p>I tried updating the broker to:</p>
  <pre><code>broker=redis://:&lt;key&gt;@&lt;server-name&gt;.redis.cache.windows.net:6380
  </code></pre>
  <p>I got this warning in Celery log:</p>
  <pre><code>[2020-12-03 20:54:00,491: WARNING/celery] Secure redis scheme specified (rediss) with no ssl options, defaulting to insecure SSL behaviour.
  </code></pre>
  <p>And this exception in django-tasks:</p>
  <pre><code>020-12-03 20:54:31,223 - INFO - runworker - Using single-threaded worker.
  2020-12-03 20:54:31,224 - INFO - runworker - Running worker against channel layer default (asgi_redis.core.RedisChannelLayer)
  2020-12-03 20:54:31,225 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconnect, websocket.receive
  Traceback (most recent call last):
    File &quot;/root/miniconda3/lib/python3.6/site-packages/redis/connection.py&quot;, line 185, in _read_from_socket
  raise socket.error(SERVER_CLOSED_CONNECTION_ERROR)
  OSError: Connection closed by server.
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;/src/manage.py&quot;, line 22, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File &quot;/root/miniconda3/lib/python3.6/site-packages/django/core/management/__init__.py&quot;, line 381, in execute_from_command_line
  utility.execute()
    File &quot;/root/miniconda3/lib/python3.6/site-packages/django/core/management/__init__.py&quot;, line 375, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
    File &quot;/root/miniconda3/lib/python3.6/site-packages/django/core/management/base.py&quot;, line 323, in run_from_argv
  self.execute(*args, **cmd_options)
    File &quot;/root/miniconda3/lib/python3.6/site-packages/django/core/management/base.py&quot;, line 364, in execute
  output = self.handle(*args, **options)
    File &quot;/root/miniconda3/lib/python3.6/site-packages/channels/management/commands/runworker.py&quot;, line 82, in handle
  worker.run()
    File &quot;/root/miniconda3/lib/python3.6/site-packages/channels/worker.py&quot;, line 87, in run
  channel, content = self.channel_layer.receive_many(channels, block=True)
    File &quot;/root/miniconda3/lib/python3.6/site-packages/asgi_redis/core.py&quot;, line 128, in receive_many
  result = connection.blpop(list_names, timeout=self.blpop_timeout)
    File &quot;/root/miniconda3/lib/python3.6/site-packages/redis/client.py&quot;, line 1550, in blpop
  return self.execute_command('BLPOP', *keys)
    File &quot;/root/miniconda3/lib/python3.6/site-packages/redis/client.py&quot;, line 772, in execute_command
  connection = pool.get_connection(command_name, **options)
    File &quot;/root/miniconda3/lib/python3.6/site-packages/redis/connection.py&quot;, line 994, in get_connection
  connection.connect()
    File &quot;/root/miniconda3/lib/python3.6/site-packages/redis/connection.py&quot;, line 502, in connect
  self.on_connect()
    File &quot;/root/miniconda3/lib/python3.6/site-packages/redis/connection.py&quot;, line 570, in on_connect
  if nativestr(self.read_response()) != 'OK':
    File &quot;/root/miniconda3/lib/python3.6/site-packages/redis/connection.py&quot;, line 637, in read_response
  response = self._parser.read_response()
    File &quot;/root/miniconda3/lib/python3.6/site-packages/redis/connection.py&quot;, line 290, in read_response
  response = self._buffer.readline()
    File &quot;/root/miniconda3/lib/python3.6/site-packages/redis/connection.py&quot;, line 224, in readline
  self._read_from_socket()
    File &quot;/root/miniconda3/lib/python3.6/site-packages/redis/connection.py&quot;, line 199, in _read_from_socket
  (e.args,))
  redis.exceptions.ConnectionError: Error while reading from socket: ('Connection closed by server.',)
  </code></pre>
  <p>I saw <a href="https://stackoverflow.com/questions/44663135/how-to-setup-celery-to-talk-ssl-to-azure-redis-instance">this question</a> and added the <code>broker_use_ssl</code>, but I am not sure how to actually use the configuration.</p>
  <p>This did not change anything:</p>
  <pre><code>app = Celery(broker=redis_url, broker_use_ssl={'cert_reqs':'ssl.CERT_REQUIRED'})
  </code></pre>
  <p>I corrected the port above and tried @Stanley Gong suggestion, including removing the quotes from the ssl.CERT_REQUIRED.  But no change in the results.</p>
  <pre><code>import ssl 
  
  app = Celery(broker=redis_url, broker_use_ssl={'cert_reqs':ssl.CERT_REQUIRED}) 
  </code></pre>