forked from platypush/platypush
Making sure that Redis constructor only initializes the attributes without creating the object and performing a connection
This commit is contained in:
parent
6ce348365f
commit
964c7b5cf0
1 changed files with 6 additions and 4 deletions
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue