Patch redis-py bug for Windows (#8386)

This commit is contained in:
mehrdadn
2020-05-12 08:41:45 -07:00
committed by GitHub
parent a3b95d4664
commit ac1ed293e3
3 changed files with 27 additions and 2 deletions
+23
View File
@@ -0,0 +1,23 @@
import errno
import socket
import sys
def patch_redis_empty_recv():
"""On Windows, socket disconnect result in errors rather than empty reads.
redis-py does not handle these errors correctly.
This patch translates connection resets to empty reads as in POSIX.
"""
assert sys.platform == "win32"
import redis
def redis_recv(sock, *args, **kwargs):
result = b""
try:
result = redis._compat.recv(sock, *args, **kwargs)
except socket.error as ex:
if ex.errno not in [errno.ECONNRESET, errno.ECONNREFUSED]:
raise
return result
redis.connection.recv = redis_recv