2016-09-15 638 views
0

我的环境: 我有三台Ubuntu服务器。 一台服务器用作使用Nginx的负载均衡器。 其他两台服务器包含完全相同的项目(与Redis相同,其中一个框是主设备,另一个是从设备)。RedisClusterException尝试使用Celery写入时

我使用 的Python, Gunicorn, Django的, 芹菜, Redis的, 哨兵程序/应用

什么我做的项目: 我有接受URL一个GET请求,对请求做一些逻辑并保存到redis中。

def save(key, value): 
    conn = redis_cluster_connect() 
    print conn 
    conn.set(key, value) 
    conn.set('bar','foo') 

这是工作的罚款时,我的连接是:

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 

但是当我使用群连接:

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

return rc 

的错误,我得到:

[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'} 

当我运行redis的-CLI,并设置在主(在服务器1)的变量i可以检索其上的从(在服务器2)

server 1: 
xxx.xx.xxx.x:6380> set test 100 
OK 

server 2: 
xxx.xx.xxx.x:6381> get test 
"100" 

当我尝试做集群槽在redis的客户机命令我得到了与上述相同的错误。

xxx.xx.xxx.x:6380> cluster slots 
(error) ERR unknown command 'cluster' 

有一点要考虑的是我的redis的配置文件不具有TCP套接字,当我试图使用TCP的Redis是行不通的。当我尝试运行redis时,它给了我一个错误。这被更改为默认Unixsocket自带默认redis.conf文件

来源:

tcp-backlog 511 

要:

unixsocket /var/run/redis/redis.sock 
unixsocketperm 700 

回答

0

你没有运行Redis的集群,所以尝试运行仅redis-cluster命令将失败。

+0

非常感谢,主控与redis集群之间我感到困惑。感谢您的澄清! – Jahedh

0

对于我来说,问题出现在版本redis-py-cluster(1.3.4)中,重新安装到版本1.3.1之后,对我来说一切正常。我想有一些问题,该版本的python软件包。

相关问题