2

我的 redis 服务器在 ubuntu 16.04 下运行,并且我运行 RQ Dashboard 来监控队列。redis 服务器有一个我为初始连接提供的密码。这是我的代码:

from rq import Queue, Connection, Worker
from redis import Redis
from dblogger import DbLogger

def _redisCon():
    redis_host = "192.168.1.169"
    redis_port = "6379"
    redis_password = "SecretPassword"
    return Redis(host=redis_host, port=redis_port, password=redis_password)

rcon = _redisCon()
if rcon is not None:
    with Connection(rcon):  
        DbLogger.log("rqworker", 0, "Launching Worker", "launching an RQ Worker - default Queue")
        worker = Worker(list(map(Queue, 'default'))) # this works - I see the worker registered in RQ dashboard
        worker.work()  # this eventually fails with the Connection error: 

"""
16:28:49 RQ worker 'rq:worker:steve-imac.95379' started, version 0.12.0
16:28:49 *** Listening on default...
16:28:49 Cleaning registries for queue: default
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/redis/connection.py", line 177, 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 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/redis/client.py", line 668, in execute_command
    return self.parse_response(connection, command_name, **options)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/redis/client.py", line 680, in parse_response
    response = connection.read_response()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/redis/connection.py", line 624, in read_response
    response = self._parser.read_response()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/redis/connection.py", line 284, in read_response
    response = self._buffer.readline()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/redis/connection.py", line 216, in readline
    self._read_from_socket()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/redis/connection.py", line 191, in _read_from_socket
    (e.args,))
redis.exceptions.ConnectionError: Error while reading from socket: ('Connection closed by server.',)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/redis/connection.py", line 489, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 61 connecting to 192.168.1.169:6379. Connection refused.
"""

我试过删除密码并在 redis.conf 中启用 unixsocket——似乎都没有帮助。这似乎发生在某种超时中,因为在其他测试中,工作人员实际上加载了一个任务并在最终死于此错误之前执行它。

4

0 回答 0