2016-08-01 8 views
0

私はherokuサイトのチュートリアルに先立ちました。私はworker.pyファイルで、この私のpython djangoアプリケーションでredisが動作しません

pip install rq 

をした

import os 

    import redis 
    from rq import Worker, Queue, Connection 

    listen = ['high', 'default', 'low'] 

    redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379') 

    conn = redis.from_url(redis_url) 

    if __name__ == '__main__': 
     with Connection(conn): 
      worker = Worker(map(Queue, listen)) 
      worker.work() 

、その後

python worker.py 

と私は、その後に行ってきました

 Traceback (most recent call last): 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 439, in connect 
     sock = self._connect() 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 494, in _connect 
     raise err 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 482, in _connect 
     sock.connect(socket_address) 
    ConnectionRefusedError: [Errno 61] Connection refused 

    During handling of the above exception, another exception occurred: 

    Traceback (most recent call last): 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 572, in execute_command 
     connection.send_command(*args) 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command 
     self.send_packed_command(self.pack_command(*args)) 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command 
     self.connect() 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 442, in connect 
     raise ConnectionError(self._error_message(e)) 
    redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused. 

    During handling of the above exception, another exception occurred: 

    Traceback (most recent call last): 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 439, in connect 
     sock = self._connect() 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 494, in _connect 
     raise err 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 482, in _connect 
     sock.connect(socket_address) 
    ConnectionRefusedError: [Errno 61] Connection refused 

    During handling of the above exception, another exception occurred: 

    Traceback (most recent call last): 
     File "worker.py", line 15, in <module> 
     worker.work() 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/rq/worker.py", line 423, in work 
     self.register_birth() 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/rq/worker.py", line 242, in register_birth 
     if self.connection.exists(self.key) and \ 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 855, in exists 
     return self.execute_command('EXISTS', name) 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 578, in execute_command 
     connection.send_command(*args) 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command 
     self.send_packed_command(self.pack_command(*args)) 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command 
     self.connect() 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 442, in connect 
     raise ConnectionError(self._error_message(e)) 
    redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused. 

次のエラーが発生しましたGoogleと私はまた、パッケージのインデックスを発見

>>> import redis 
>>> r = redis.StrictRedis(host='localhost', port=6379, db=0) 
>>> r.set('foo', 'bar') 

ヒットは、多かれ少なかれ、これらのチュートリアルが求めるものを入力し、Enterとノー行っている次のようなメッセージ

 Traceback (most recent call last): 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 439, in connect 
     sock = self._connect() 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 494, in _connect 
     raise err 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 482, in _connect 
     sock.connect(socket_address) 
    ConnectionRefusedError: [Errno 61] Connection refused 

    During handling of the above exception, another exception occurred: 

    Traceback (most recent call last): 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 572, in execute_command 
     connection.send_command(*args) 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command 
     self.send_packed_command(self.pack_command(*args)) 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command 
     self.connect() 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 442, in connect 
     raise ConnectionError(self._error_message(e)) 
    redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused. 

    During handling of the above exception, another exception occurred: 

    Traceback (most recent call last): 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 439, in connect 
     sock = self._connect() 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 494, in _connect 
     raise err 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 482, in _connect 
     sock.connect(socket_address) 
    ConnectionRefusedError: [Errno 61] Connection refused 

    During handling of the above exception, another exception occurred: 

    Traceback (most recent call last): 
     File "<stdin>", line 1, in <module> 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 1072, in set 
     return self.execute_command('SET', *pieces) 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 578, in execute_command 
     connection.send_command(*args) 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command 
     self.send_packed_command(self.pack_command(*args)) 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command 
     self.connect() 
     File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 442, in connect 
     raise ConnectionError(self._error_message(e)) 
    redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused. 

を持っている続いています。どうすればこの作品を作れますか?

答えて

0

redis serverを実行する必要があります。コンソールでredis-serverと入力してサーバを起動します(Mac OSX)。

$redis-server 

あなたのアプリと通信するには、作業者がブローカー(redis)を必要とすることを覚えておいてください。

+0

このメッセージが表示されるのは、bash:redis-server:command not foundです。ローカルにインストールするか、グローバルにインストールするのですか?私は私のvirtualenv内からこれをやっているからです。私が読んでいるドキュメントでは、それが指定されていません。 – losee

+0

@loseeあなたはそれをグローバルにインストールしなければなりません、redisはpythonのパッケージやアプリケーションではありません。サーバーを起動するコマンドは、お使いのOSによって異なります。 – levi

+0

brewがインストールされており、redis-serverをヒットして動作しました。第一歩。 – losee

関連する問題