我首先按照heroku网站上的教程进行操作。我这样做了
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()
然后在worker.py文件中
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.
我收到以下错误
>>> import redis
>>> r = redis.StrictRedis(host='localhost', port=6379, db=0)
>>> r.set('foo', 'bar')
然后我去google找到了我也遵循的包索引
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.
按Enter键并收到以下消息
cmd.script
我已经完成了这些教程所要求的内容。我怎样才能做到这一点?
答案 0 :(得分:0)
您需要运行redis服务器。在控制台上键入redis-server以启动服务器(Mac OSX)。
$redis-server
请记住,工作人员需要经纪人(redis)才能与您的应用进行通信。