2018-05-22 16:44:17 +02:00
|
|
|
from redis import Redis
|
|
|
|
|
2018-07-06 02:08:38 +02:00
|
|
|
from platypush.plugins import Plugin, action
|
2018-05-22 16:44:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
class RedisPlugin(Plugin):
|
2018-06-25 19:57:43 +02:00
|
|
|
"""
|
|
|
|
Plugin to send messages on Redis queues.
|
|
|
|
|
|
|
|
Requires:
|
|
|
|
|
|
|
|
* **redis** (``pip install redis``)
|
|
|
|
"""
|
|
|
|
|
2018-07-06 02:26:54 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2018-07-06 02:08:38 +02:00
|
|
|
@action
|
2018-05-22 16:44:17 +02:00
|
|
|
def send_message(self, queue, msg, *args, **kwargs):
|
2018-06-25 19:57:43 +02:00
|
|
|
"""
|
|
|
|
Send a message to a Redis queu.
|
|
|
|
|
|
|
|
:param queue: Queue name
|
|
|
|
:type queue: str
|
|
|
|
|
|
|
|
:param msg: Message to be sent
|
|
|
|
:type msg: str, bytes, list, dict, Message object
|
|
|
|
|
|
|
|
:param args: Args passed to the Redis constructor (see https://redis-py.readthedocs.io/en/latest/#redis.Redis)
|
|
|
|
:type args: list
|
|
|
|
|
|
|
|
:param kwargs: Kwargs passed to the Redis constructor (see https://redis-py.readthedocs.io/en/latest/#redis.Redis)
|
|
|
|
:type kwargs: dict
|
|
|
|
"""
|
|
|
|
|
2018-05-22 16:44:17 +02:00
|
|
|
redis = Redis(*args, **kwargs)
|
|
|
|
redis.rpush(queue, msg)
|
|
|
|
|
|
|
|
|
|
|
|
# vim:sw=4:ts=4:et:
|
|
|
|
|