Slide 30
Slide 30 text
pooling redis pub/sub
pipe = Queue()
pipe.put(‘subscribe’, ‘thread:12345’)
pipe.put(‘unsubscribe’, ‘forum:cnn’)
... elsewhere ...
# new way is
def listener(pubsub, pipe):
for data in pubsub.listen():
# handle data here...
# handle new subscriptions
if not pipe.empty():
action, channel = pipe.get_nowait()
getattr(pubsub, action)(channel)
Thursday, March 21, 13
this is spawned in a thread
heartbeat
goal is to minimize redis connections but pubsub isn’t thread safe, and they mean it
[q.put(data) for q in channel_proxy[data.channel]]