断管错误Redis

cha*_*ndu 3 python sockets redis redis-py

我们正在尝试通过 redis-py 包将大小为 2.3GB 的腌制对象 SET 到 redis 中。遇到以下错误。

BrokenPipeError: [Errno 32] 管道损坏

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

我想了解根本原因。是由于服务器端还是客户端的输入/输出缓冲区限制?是否由于 RESP 协议的任何限制?是否允许将 2.3 Gb 的单个值(字节)存储到 Redis 中?

导入redis

r = redis.StrictRedis(host='10.XXX', port=7000, db=0)

pickled_object = pickle.dumps(obj_to_be_pickled)

r.set('some_key',pickled_object)

客户端错误

BrokenPipeError: [Errno 32] 管道损坏

/usr/local/lib/python3.4/site-packages/redis/connection.py(544)send_packed_command()

self._sock.sendall(item)

服务器端错误

31164:M 04 Apr 06:02:42.334 - 来自客户端的协议错误:id=95 addr=10.2.130.144:36120 fd=11 name= age=0 idle=0 flags=N db=0 sub=0 psub=0 multi =-1 qbuf=16384 qbuf-free=16384 obl=42 oll=0 omem=0 events=r cmd=NULL

31164:M 04 Apr 06:07:09.591 - 来自客户端的协议错误:id=96 addr=10.2.130.144:36139 fd=11 name=age=9 idle=0 flags=N db=0 sub=0 psub=0 multi =-1 qbuf=40 qbuf-free=32728 obl=42 oll=0 omem=0 events=r cmd=NULL

Redis 版本:3.2.8 / 64 位

cha*_*ndu 6

问题在于传递给 Redis 的数据大小。该命令被发送到 Redis,因为有两个项目遵循 RESP 标准

项目#1

b'*3\r\n$3\r\nSET\r\n$8\r\nsome_key\r\n$2460086692\r\n'

Where
    *3           - indicates RESP array of three elements
    \r\n         - indicates the RESP Carriage return Line Feeder(separator)
    $3           - indicates Bulk string of length 3 bytes(here it is 'SET')
    $8           - indicates Bulk String of length 8 bytes(he it is 'some_key')
    $2460086692  - indicates Bulk String of length 2460086692 bytes (the length of value 2460 MB to be passed to Redis as next item )
Run Code Online (Sandbox Code Playgroud)

项目#2

b'\x80\x03csklearn.ensemble.forest\nRandomForestC...

Here item #2 indicates the actual data
Run Code Online (Sandbox Code Playgroud)
  • 当 item #1 指令传递到 Redis 服务器时,服务器关闭了连接,因为值 $2460086692 违反了 512 MB 的协议规则
  • 当项目 #2 发送到 Redis 服务器时,我们收到 Broken Pipe 异常,因为服务器已关闭连接。


Ita*_*ber 5

Redis 的 String 数据类型最大可以为 512MB。