From cccb48c53308b6d00d725e545435a002e7f10350 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 6 Sep 2018 03:38:10 +0200 Subject: [PATCH] Implemented mget and mset actions for Redis plugin --- platypush/plugins/redis.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/redis.py b/platypush/plugins/redis.py index 38b369d409..89eb999425 100644 --- a/platypush/plugins/redis.py +++ b/platypush/plugins/redis.py @@ -13,7 +13,12 @@ class RedisPlugin(Plugin): """ def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) + super().__init__() + self.args = args + self.kwargs = kwargs + + def _get_redis(self): + return Redis(*self.args, **self.kwargs) @action def send_message(self, queue, msg, *args, **kwargs): @@ -36,6 +41,21 @@ class RedisPlugin(Plugin): redis = Redis(*args, **kwargs) redis.rpush(queue, msg) + @action + def mget(self, keys, *args): + """ + :returns: A list of values as specified in `keys` (wraps MGET) + """ + + return self._get_redis().mget(keys, *args)[0].decode() + + @action + def mset(self, *args, **kwargs): + """ + Set key/values based on mapping (wraps MSET) + """ + + return self._get_redis().mset(*args, **kwargs) # vim:sw=4:ts=4:et: