python - python-redis:ConnectionError:写入套接字时发生错误32。 pipe 坏了?

标签 python redis

我要测试redis的值可以支持高达512MB
语言:python

import redis
conn = redis.Redis()
temp_dict={}
for i in range(1000000):
    temp_dict.update({str(i):str(i)})
conn.hmset('hash-key',temp_dict)

错误:
-------------------------------------------------- -------------------------
ConnectionError追溯(最近一次通话)
在()中
----> 1 conn.hmset('hash-key',temp_dict)
/usr/local/lib/python2.7/dist-packages/redis/client.pyc in hmset(self, name, mapping)
   2009         for pair in iteritems(mapping):
   2010             items.extend(pair)
-> 2011         return self.execute_command('HMSET', name, *items)
   2012 
   2013     def hmget(self, name, keys, *args):

/usr/local/lib/python2.7/dist-packages/redis/client.pyc in execute_command(self, *args, **options)
    671             if not connection.retry_on_timeout and isinstance(e, TimeoutError):
    672                 raise
--> 673             connection.send_command(*args)
    674             return self.parse_response(connection, command_name, **options)
    675         finally:

/usr/local/lib/python2.7/dist-packages/redis/connection.pyc in send_command(self, *args)
    608     def send_command(self, *args):
    609         "Pack and send a command to the Redis server"
--> 610         self.send_packed_command(self.pack_command(*args))
    611 
    612     def can_read(self, timeout=0):

/usr/local/lib/python2.7/dist-packages/redis/connection.pyc in send_packed_command(self, command)
    601                 errmsg = e.args[1]
    602             raise ConnectionError("Error %s while writing to socket. %s." %
--> 603                                   (errno, errmsg))
    604         except:
    605             self.disconnect()

ConnectionError: Error 104 while writing to socket. Connection reset by peer.

最佳答案

可能一次插入的数据太大,并且数据可以分开,一次只能存储100000条数据。

import redis
conn = redis.Redis()

for x in range(10): 
    temp_dict={}
    for i in range(100000):
        temp_dict.update({str(i):str(i)})
    conn.hmset('hash-key',temp_dict)

关于python - python-redis:ConnectionError:写入套接字时发生错误32。 pipe 坏了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47543929/

相关文章:

Python - 非常奇怪的 sys.path 行为

javascript - Django AJAX 返回未定义而不是变量

python - 在 Python 2.7 中创建一个矩形星号

caching - Redis 缓存驱动程序在 PHPUnit 中抛出异常

java - 在 docker 中启动 spring session + redis 时出错

python - 代码在命令提示符下逐行运行,但是当我整体运行文件时出现新问题

python - REST API 的 url 缓存系统的最有效查找

node.js - https 上的 Socketio 使用 redis

redis - 在redis中获取哈希的所有键

java - 从 redis SET 中获取成员是否会将所有内容都获取到内存中?