Implemented mget and mset actions for Redis plugin

This commit is contained in:
Fabio Manganiello 2018-09-06 03:38:10 +02:00
parent 63890f7670
commit cccb48c533

View file

@ -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: