Redis 连接 localhost:6379 时出现错误 8。提供节点名或服务名,或未知

问题描述 投票:0回答:4

我的环境是Mac OS 10.9.2,python3.3,redis-2.6.9(64位)。

我有很多线程(近2000个)使用同一个redis实例来写入数据,但有些线程抛出以下异常:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/site-packages/redis/connection.py", line 250, in connect
    sock = self._connect()
  File "/usr/local/lib/python3.3/site-packages/redis/connection.py", line 268, in _connect
    self.socket_timeout)
  File "/usr/local/Cellar/python3/3.3.4/Frameworks/Python.framework/Versions/3.3/lib/python3.3/socket.py", line 417, in create_connecti
on
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.3.4/Frameworks/Python.framework/Versions/3.3/lib/python3.3/threading.py", line 901, in _bootstrap_i
nner
    self.run()
  File "/usr/local/Cellar/python3/3.3.4/Frameworks/Python.framework/Versions/3.3/lib/python3.3/threading.py", line 858, in run
    self._target(*self._args, **self._kwargs)
  File "proxypool.py", line 289, in _efficiency_proxy
    self.rdb.zadd(db_proxy, time_delay, proxy)
  File "/usr/local/lib/python3.3/site-packages/redis/client.py", line 1345, in zadd
    return self.execute_command('ZADD', name, *pieces)
  File "/usr/local/lib/python3.3/site-packages/redis/client.py", line 464, in execute_command
    connection.send_command(*args)
  File "/usr/local/lib/python3.3/site-packages/redis/connection.py", line 334, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "/usr/local/lib/python3.3/site-packages/redis/connection.py", line 316, in send_packed_command
    self.connect()
  File "/usr/local/lib/python3.3/site-packages/redis/connection.py", line 253, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 8 connecting localhost:6379. nodename nor servname provided, or not known.

有什么办法可以解决这个问题吗?
我尝试在发生此异常时连接redis服务器并使用

ulimit -n
设置更大的数字,但这两种方法都不起作用。

python macos redis python-3.3
4个回答
5
投票

我知道为什么会这样。这是由 redis-server 的最大连接数引起的,并且与操作系统设置的最大文件处理程序数有关。
如果我设置:

$ ulimit -n 1024

它有效。


2
投票

我也遇到这个问题了

当您使用错误的 Redis HOST 时,您也会遇到该错误。


2
投票

很可能 reds 服务器没有运行。使用“redis-server”命令运行它。

brew services start redis (on mac)

0
投票

我遇到了同样的问题,唯一有效的解决方案是更新 django-redis

使用点

pip install --upgrade django-redis

或者如果你使用的是pipenv

pipenv update django-redis
© www.soinside.com 2019 - 2024. All rights reserved.