RedisClusterException when trying to write using Celery
<p><strong>My environment:</strong>
I have three Ubuntu servers.
One server is used as a load balancer using Nginx.
The other two servers contain the exact same project (are identical apart from redis where one box is the master and other is the slave).</p>

<p><strong>The Programs/Applications I'm using</strong>
Python,
Gunicorn,
Django,
Celery,
Redis,
Sentinel</p>

<p><strong>What My project does:</strong>
I have a URL which takes in a GET request, does some logic regarding the request and saves into redis. </p>

<pre><code>def save(key, value):
    conn = redis_cluster_connect()
    print conn
    conn.set(key, value)
    conn.set('bar','foo')
</code></pre>

<p>This was working fine when my connection was:</p>

<pre><code>def redis_connect():
    print 'redis connected'
    return redis.Redis(host="xxx.xx.xxx.x", port=6380, db=1) # CHANGE TO THE REDIS PORT THAT IS ACTIVE
</code></pre>

<p>But when I use the cluster connection:</p>

<pre><code>def redis_cluster_connect():
    startup_nodes = [{"host": "xxx.xx.xxx.x", "port": "6380"}]
    rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)

return rc
</code></pre>

<p><strong>The Error I get:</strong></p>

<pre><code>[2016-09-15 13:28:59,682: INFO/MainProcess] Received task: testapp.tasks.mobilise_stops[cc64c425-bd37-4896-b6ab-4319de5fb743]
    [2016-09-15 13:28:59,684: WARNING/Worker-1] Oh no! Task failed: RedisClusterException("ERROR sending 'cluster slots' command to redis server: {'host': 'xxx.xx.xxx.x', 'port': '6380'}",)
    [2016-09-15 13:28:59,685: ERROR/MainProcess] Task testapp.tasks.mobilise_stops[cc64c425-bd37-4896-b6ab-4319de5fb743] raised unexpected: RedisClusterException("ERROR sending 'cluster slots' command to redis server: {'host': 'xxx.xx.xxx.x', 'port': '6380'}",)
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
        R = retval = fun(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 438, in __protected_call__
        return self.run(*args, **kwargs)
      File "/var/www/gateway/venv/gateway/testapp/tasks.py", line 50, in mobilise_stops
        save(mobilise_stops.request.id, 'Success')
      File "/var/www/gateway/venv/gateway/testapp/tasks.py", line 28, in save
        conn = redis_cluster_connect()
      File "/var/www/gateway/venv/gateway/testapp/tasks.py", line 19, in redis_cluster_connect
        rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)
      File "/usr/local/lib/python2.7/dist-packages/rediscluster/client.py", line 157, in __init__
        **kwargs
      File "/usr/local/lib/python2.7/dist-packages/rediscluster/connection.py", line 83, in __init__
        self.nodes.initialize()
      File "/usr/local/lib/python2.7/dist-packages/rediscluster/nodemanager.py", line 148, in initialize
        raise RedisClusterException("ERROR sending 'cluster slots' command to redis server: {0}".format(node))
    RedisClusterException: ERROR sending 'cluster slots' command to redis server: {'host': 'xxx.xx.xxx.x', 'port': '6380'}
</code></pre>

<p>When I run redis-cli and set a variable on the master (on server 1) I can retrieve it on the slave (on server 2)</p>

<pre><code>server 1:
xxx.xx.xxx.x:6380&gt; set test 100
OK

server 2:
xxx.xx.xxx.x:6381&gt; get test 
"100"
</code></pre>

<p>When I try doing the cluster slots command in the redis client I get the same error as the above. </p>

<pre><code>xxx.xx.xxx.x:6380&gt; cluster slots
(error) ERR unknown command 'cluster'
</code></pre>

<p>One thing to consider is my redis config file doesn't have a tcp socket, when I tried using tcp redis would not work. It gave me an error when I tried running redis. This was changed to the default Unixsocket that comes in the default redis.conf file</p>

<p>From:</p>

<pre><code>tcp-backlog 511
</code></pre>

<p>To:</p>

<pre><code>unixsocket /var/run/redis/redis.sock
unixsocketperm 700
</code></pre>

<p>You are not running a redis cluster, so attempting to run redis-cluster only commands are going to fail. </p>

python django sockets redis redis-cluster