You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
When I start a python thread to calculate data and set to Redis.
I found about 30 minutes, will throw a exception:
self.pipe.execute()
File "/usr/local/lib/python3.4/dist-packages/redis/client.py", line 2626, in execute
return execute(conn, stack, raise_on_error)
File "/usr/local/lib/python3.4/dist-packages/redis/client.py", line 2503, in
execute_transaction
self.parse_response(connection, '
')
File "/usr/local/lib/python3.4/dist-packages/redis/client.py", line 2584, in parse_response
self, connection, command_name, **options)
File "/usr/local/lib/python3.4/dist-packages/redis/client.py", line 585, in parse_response
response = connection.read_response()
File "/usr/local/lib/python3.4/dist-packages/redis/connection.py", line 577, in read_response
response = self._parser.read_response()
File "/usr/local/lib/python3.4/dist-packages/redis/connection.py", line 238, in read_response
response = self._buffer.readline()
File "/usr/local/lib/python3.4/dist-packages/redis/connection.py", line 168, in readline
self._read_from_socket()
File "/usr/local/lib/python3.4/dist-packages/redis/connection.py", line 130, in _read_from_socket
buf.write(data)
ValueError: I/O operation on closed file.
It looks like socket connection disconnect ?
class KVStore:
def __init__(self, host, port, password):
self.r = redis.StrictRedis(host=host, port=port, password=password)
self.pipe = self.r.pipeline()
self.set_count = 0
self.MAX_SET = 1000
def set(self, key, value, timeout=None, force=None):
if force is None:
force = False
self.pipe.set(key, o2s(value), timeout)
self.set_count += 1
if force:
self.submit()
else:
if self.set_count > self.MAX_SET:
self.submit()
def submit(self):
if self.set_count != 0:
#logger.debug('kv_store|submit|%d', self.set_count)
self.pipe.execute()
self.set_count = 0
def get(self, key):
value = self.r.get(key)
return s2o(value)
def delete(self, key):
self.r.delete(key)
def exists(self, key):
return self.r.exists(key)
def count(self):
return self.r.dbsize()
repeat set key value, and submit.