forked from platypush/platypush
Redis plugin added and Redis backend made more robust to work also with single-quoted JSON-like strings returned by the Redis lib
This commit is contained in:
parent
18efdb1c70
commit
f4da6ebb1b
2 changed files with 26 additions and 2 deletions
|
@ -42,8 +42,15 @@ class RedisBackend(Backend):
|
||||||
|
|
||||||
while not self.should_stop():
|
while not self.should_stop():
|
||||||
try:
|
try:
|
||||||
msg = self.redis.blpop(self.queue)
|
msg = self.redis.blpop(self.queue)[1].decode('utf-8')
|
||||||
msg = Message.build(json.loads(msg[1].decode('utf-8')))
|
|
||||||
|
try:
|
||||||
|
msg = Message.build(json.loads(msg))
|
||||||
|
except:
|
||||||
|
import ast
|
||||||
|
msg = Message.build(ast.literal_eval(msg))
|
||||||
|
|
||||||
|
logging.info('Received message on the Redis backend: {}'.format(msg))
|
||||||
self.bus.post(msg)
|
self.bus.post(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
|
|
17
platypush/plugins/redis.py
Normal file
17
platypush/plugins/redis.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from redis import Redis
|
||||||
|
|
||||||
|
from platypush.message.response import Response
|
||||||
|
from platypush.plugins import Plugin
|
||||||
|
|
||||||
|
|
||||||
|
class RedisPlugin(Plugin):
|
||||||
|
def send_message(self, queue, msg, *args, **kwargs):
|
||||||
|
redis = Redis(*args, **kwargs)
|
||||||
|
redis.rpush(queue, msg)
|
||||||
|
return Response(output={'state': 'ok'})
|
||||||
|
|
||||||
|
|
||||||
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue