From 964c7b5cf08cc74fac551e641068ec1e05e6e0df Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 25 Oct 2018 20:06:29 +0200 Subject: [PATCH] Making sure that Redis constructor only initializes the attributes without creating the object and performing a connection --- platypush/backend/redis.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platypush/backend/redis.py b/platypush/backend/redis.py index cdb2f2be3..3c335dddc 100644 --- a/platypush/backend/redis.py +++ b/platypush/backend/redis.py @@ -31,19 +31,21 @@ class RedisBackend(Backend): self.queue = queue self.redis_args = redis_args - self.redis = Redis(**self.redis_args) + self.redis = None + def _get_redis(self): + return Redis(**self.redis_args) def send_message(self, msg, queue_name=None): if queue_name: - self.redis.rpush(queue_name, msg) + self._get_redis().rpush(queue_name, msg) else: - self.redis.rpush(self.queue, msg) + self._get_redis().rpush(self.queue, msg) def get_message(self, queue_name=None): queue = queue_name or self.queue - msg = self.redis.blpop(queue)[1].decode('utf-8') + msg = self._get_redis().blpop(queue)[1].decode('utf-8') try: msg = Message.build(json.loads(msg))