python-redis:ConnectionError:写入套接字时出错32。破管?

时间:2017-11-29 02:10:02

标签: python redis

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

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 Traceback(最近一次调用最后一次)      in()     ----> 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.

1 个答案:

答案 0 :(得分:0)

也许一次插入的数据太大,并且可以分离数据,一次只能存储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)