From 22a0fcd865b618cbbbfd102efd88a7983507c24e Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Mon, 15 Nov 2010 12:53:31 +0100 Subject: [PATCH] Close Redis connection on channel close. Thanks to David Wolever. This needs more testing --- ghettoq/backends/pyredis.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ghettoq/backends/pyredis.py b/ghettoq/backends/pyredis.py index 10dc5a4..7888c08 100644 --- a/ghettoq/backends/pyredis.py +++ b/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: + pass + try: + self.connection.connection.disconnect() + except (AttributeError, ResponseError): + pass