Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Close Redis connection on channel close. Thanks to David Wolever. Thi…

…s needs more testing
  • Loading branch information...
commit 22a0fcd865b618cbbbfd102efd88a7983507c24e 1 parent 8cc59fd
Ask Solem authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 ghettoq/backends/pyredis.py
View
13 ghettoq/backends/pyredis.py
@@ -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)
@@ -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:
@thomasst
thomasst added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ pass
+ try:
+ self.connection.connection.disconnect()
+ except (AttributeError, ResponseError):
+ pass

0 comments on commit 22a0fcd

Please sign in to comment.
Something went wrong with that request. Please try again.