Search code examples
pythonpython-3.xredispublish-subscribe

Pop message from channel in Redis


I need to publish messages on one machine(setter) in specific channel and get it on other machines(handlers). The problem is that each handler should process unique message.

As I can see in documentation, there is no standard method to pop messages from channel, maybe I try to use it in wrong way?

Here is code of handler:

 import redis

 r=redis.Redis()
 pubsub = r.pubsub()
 pubsub.subscribe('test_channel')
 for item in self.pubsub.listen():
    ...

Here is the code of setter:

import redis

r = redis.Redis()
r.publish('test_channel', 'test message')

Solution

  • Pub/Sub doesn't fit this pattern - look into using a List and call blocking pop operations in the handlers instead.