Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rediserver/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

__version__ = "0.0.1"
__version__ = "0.0.2"
33 changes: 12 additions & 21 deletions rediserver/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,28 @@ def _parse_line(self):
self.can_read = False
self._process_data()

def _response_done(self, response):
resp = self.wfile.getvalue()
self.wfile = cStringIO.StringIO()
self.data = []
self.push(resp)
self.close_when_done()

def _process_data(self):
response = Response(self.wfile.write)
try:
cmd = InputParser(self.data).read_response()
self.server._callback(cmd, response, self)
if not response.dirty:
raise Exception("no response")
except Exception, e:
response.error(u"ERR: %s" % e)
raise
finally:
resp = self.wfile.getvalue()
self.wfile = cStringIO.StringIO()
self.data = []

# write the data out async; close_when_done actually
# causes handle_close to be called, and we unblock and
# enable reads again.
self.push(resp)
self.close_when_done()

cmd = InputParser(self.data).read_response()
self.server._callback(cmd, response, self._response_done)

class AsyncoreServer(asyncore.dispatcher):
protocol_handler = RedisProtocolHandler
allow_address_reuse = True
backlog = 1024

def __init__(self, ip, port, callback, ):
def __init__(self, ip, port, callback, select_timeout=30.0):
self.ip = ip
self.port = port
self._callback = callback
self.select_timeout = select_timeout
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
if self.allow_address_reuse:
Expand All @@ -117,7 +108,7 @@ def __init__(self, ip, port, callback, ):

def serve_forever(self):
"""Starts the asyncore IO loop."""
asyncore.loop()
asyncore.loop(timeout=self.select_timeout)

def handle_accept(self):
try:
Expand Down
2 changes: 1 addition & 1 deletion rediserver/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def encode(self, value):
elif isinstance(value, bool):
self._write(':%d\r\n' % (1 if value else 0))
else:
self._bulk(v)
self._bulk(value)

def status(self, msg="OK"):
"""Send a status."""
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
url="https://github.com/ninowalker/py-redis-server",
license = "BSD",
packages=['rediserver'],
long_description=open('README.md').read(),
install_requires=['redis>=2.4.1'],
setup_requires=['nose>=1.0', 'coverage', 'nosexcover'],
test_suite = 'nose.collector',
Expand Down