ConnectionError:写入套接字时出现错误104。对等方重置连接

时间:2020-11-11 08:57:27

标签: python-3.x pandas dataframe sockets redis

ConnectionError:写入套接字时出现错误104。对等方重置连接。

环境: Ubuntu的:16.04 的Python:3.6 PC总内存:32G

我已经安装了redis'3.0.6'。

当您尝试插入500,000个数据时成功,但是当您尝试插入4000万个大数据时失败。

尝试将Python数据帧插入Redis时,由于容量太大而失败。

数据插入成功:

 1. r = redis.StrictRedis(host='localhost', port=6379, db=0)
 2.log_df_50.shape
   -> (500000, 6)
 3.r.setex('log_df_50',100,log_df_50.to_json())
   -> True

数据插入失败:

 1.r = redis.StrictRedis(host='localhost', port=6379, db=0)
 2. log_df.shape
   -> (41757802, 6)
 3. r.setex('session',100,log_df.to_json())

ConnectionResetError追溯(最近一次通话) 〜/ anaconda3 / envs / Colabo / lib / python3.6 / site-packages / redis / connection.py 在send_packed_command中(自己,命令,check_health) 705对于命令中的项目: -> 706 sendall(self._sock,项目) 707,除了socket.timeout:

〜/ anaconda3 / envs / Colabo / lib / python3.6 / site-packages / redis / _compat.py 在sendall(袜子,* args,** kwargs) 8 def sendall(袜子,* args,** kwargs): ----> 9 return sock.sendall(* args,** kwargs) 10

ConnectionResetError:[Errno 104]对等重置连接

在处理上述异常期间,发生了另一个异常:

ConnectionError跟踪(最近一次通话) 在 ----> 1个r.setex('session',100,log_df.to_json())

〜/ anaconda3 / envs / Colabo / lib / python3.6 / site-packages / redis / client.py在 setex(self,name,time,value)1820 if isinstance(时间, datetime.timedelta):1821年= int(time.total_seconds()) -> 1822 return self.execute_command('SETEX',name,time,value)1823 1824 def setnx(self,name,value):

〜/ anaconda3 / envs / Colabo / lib / python3.6 / site-packages / redis / client.py在 execute_command(self,* args,** options) 898 conn = self.connection或pool.get_connection(command_name,** options) 899尝试: -> 900 conn.send_command(* args) 901 return self.parse_response(conn,command_name,** options) 902除了(ConnectionError,TimeoutError)为e:

〜/ anaconda3 / envs / Colabo / lib / python3.6 / site-packages / redis / connection.py 在send_command(self,* args,** kwargs)中 724“打包并将命令发送到Redis服务器” 第725章(小幸运) -> 726 check_health = kwargs.get('check_health',True)) 727 728 def can_read(self,timeout = 0):

〜/ anaconda3 / envs / Colabo / lib / python3.6 / site-packages / redis / connection.py 在send_packed_command中(自己,命令,check_health) 716 errmsg = e.args [1] 717提高ConnectionError(“写入套接字时错误%s。%s。”% -> 718(errno,errmsg)) 719除了BaseException: 720 self.disconnect()

ConnectionError:写入套接字时出现错误104。连接重置 通过同行。

关于原因的任何提示?

如何将Python大容量数据帧插入Redis?

我应该怎么解决这个问题?

2 个答案:

答案 0 :(得分:1)

我认为问题在于 Redis 协议中键/值的 512 MB 限制。
https://redis.io/topics/protocol
https://redis.io/topics/data-types-intro

现在你无能为力。

您可能只需要将数据帧切成更小的部分。

更新:
您还可以使用较新的 Redis(最低 5.0)并在 proto-max-bulk-len 中增加 redis.confhttps://github.com/redis/redis/issues/7354
我还必须增加 client-query-buffer-limit

答案 1 :(得分:-1)

我有同样的问题。 在

中设置 ssl = True

1. r = redis.StrictRedis(host='localhost', port=6379, db=0, ssl=True)

为我解决了