diff --git a/platypush/backend/redis.py b/platypush/backend/redis.py index 3d4dd0e06e..b1d80534c1 100644 --- a/platypush/backend/redis.py +++ b/platypush/backend/redis.py @@ -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) diff --git a/platypush/plugins/redis.py b/platypush/plugins/redis.py index dfce8d5171..6cd62f3819 100644 --- a/platypush/plugins/redis.py +++ b/platypush/plugins/redis.py @@ -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):