Made Redis backend and plugin more robust.
- Redis arguments read either from the backend or the plugin configuration as a fallback in case of partial conf - send_message now falls back on the default Redis connection configuration if *args and **kwargs are missing
This commit is contained in:
parent
8fe4d77e3d
commit
c8f7eb30aa
2 changed files with 25 additions and 2 deletions
|
@ -3,6 +3,7 @@ import json
|
|||
from redis import Redis
|
||||
|
||||
from platypush.backend import Backend
|
||||
from platypush.context import get_plugin
|
||||
from platypush.message import Message
|
||||
|
||||
|
||||
|
@ -31,6 +32,15 @@ class RedisBackend(Backend):
|
|||
|
||||
self.queue = queue
|
||||
self.redis_args = redis_args
|
||||
|
||||
if not redis_args:
|
||||
try:
|
||||
redis_plugin = get_plugin('redis')
|
||||
if redis_plugin and redis_plugin.kwargs:
|
||||
self.redis_args = redis_plugin.kwargs
|
||||
except:
|
||||
pass
|
||||
|
||||
self.redis = Redis(**self.redis_args)
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from redis import Redis
|
||||
|
||||
from platypush.context import get_backend
|
||||
from platypush.plugins import Plugin, action
|
||||
|
||||
|
||||
|
@ -17,6 +18,14 @@ class RedisPlugin(Plugin):
|
|||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
|
||||
if not kwargs:
|
||||
try:
|
||||
redis_backend = get_backend('redis')
|
||||
if redis_backend and redis_backend.redis_args:
|
||||
self.kwargs = redis_backend.redis_args
|
||||
except:
|
||||
pass
|
||||
|
||||
def _get_redis(self):
|
||||
return Redis(*self.args, **self.kwargs)
|
||||
|
||||
|
@ -38,8 +47,12 @@ class RedisPlugin(Plugin):
|
|||
:type kwargs: dict
|
||||
"""
|
||||
|
||||
redis = Redis(*args, **kwargs)
|
||||
redis.rpush(queue, str(msg))
|
||||
if args or kwargs:
|
||||
redis = Redis(*args, **kwargs)
|
||||
else:
|
||||
redis = self._get_redis()
|
||||
|
||||
return redis.rpush(queue, str(msg))
|
||||
|
||||
@action
|
||||
def mget(self, keys, *args):
|
||||
|
|
Loading…
Reference in a new issue