Skip to content

Commit

Permalink
Close Redis connection on channel close. Thanks to David Wolever. Thi…
Browse files Browse the repository at this point in the history
…s needs more testing
  • Loading branch information
Ask Solem committed Nov 15, 2010
1 parent 8cc59fd commit 22a0fcd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ghettoq/backends/pyredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, host=None, port=None, user=None, password=None,
database, timeout)

def establish_connection(self):
self.port = int(self.port) or DEFAULT_PORT
self.port = int(self.port or DEFAULT_PORT)
return Redis(host=self.host, port=self.port, db=self.database,
password=self.password)

Expand Down Expand Up @@ -61,3 +61,14 @@ def purge(self, queue):
size = self.client.llen(queue)
self.client.delete(queue)
return size

def close(self):
if self.connection is not None:
try:
self.connection.bgsave()
except ResponseError:

This comment has been minimized.

Copy link
@thomasst

thomasst Dec 3, 2010

ResponseError is not imported. Also, since Redis autosaves, I do not think it's the client's responsibility to bgsave().

pass
try:
self.connection.connection.disconnect()
except (AttributeError, ResponseError):
pass

0 comments on commit 22a0fcd

Please sign in to comment.