使用REDIS实施动态会员协议,以保持工人的客户列表更新

发布于 2025-02-07 05:41:49 字数 370 浏览 2 评论 0原文

我正在使用Python中的XMLRPC进行大师工作者的架构分配,现在我应该实现动态成员资格协议,以便每当主人修改它(添加或删除工人)时,客户端上的工人列表就会更新,以便客户端不需要在运行命令之前或在运行命令之前请求它。

老师提到的可以通过事件或小组沟通来完成(我将向Ping工人实施经理节点,这也需要相同的动态协议),所以我考虑使用基于事件的架构的插座,但老师告诉我我更好使用REDIS或RABBITMQ使用间接通信。

问题是我真的不知道如何在python上实现redis消息侦听器,因为我只是找到的阻止示例,而true则是redis.get_message()大多数大多数时间(使用redis-py)。你能帮我吗?

非常感谢。

I am doing a master-worker architecture assignment with XMLRPC in Python and now I am supposed to implement a dynamic membership protocol so the workers list on the client gets updated everytime the master modifies it (worker added or deleted) so the client does not need to request it manually or before running a command.

The teacher mentioned it can be done through events or group communication (I will implement a manager node to ping workers which also needs the same dynamic protocol) so I thought about using sockets which is an event based architecture but the teacher told me I am better off using indirect communication with Redis or RabbitMQ.

The thing is I do not really know how to implement a Redis message listener on Python since I just find blocking examples with while True followed by redis.get_message() most of the time (using redis-py). Could you help me with that?

Thanks a lot in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜宝宝 2025-02-14 05:41:49

多亏了Redis的Discord Server上的Mephalich,我发现了一种有趣的方法,可以实现使用run_in_thread

import redis
def hnd(msg):
   print(msg)
  # some real work  should be done in this handler over the msg arrived through the pubsub channel


r = redis.Redis(...)
p = r.pubsub()
p.psubscribe(**{'cmdchannels*': hnd})
thread = p.run_in_thread(sleep_time=0.001)

Thanks to Mephalich on Redis' Discord server I discovered an interesting way to achieve that which consists of using run_in_thread.

import redis
def hnd(msg):
   print(msg)
  # some real work  should be done in this handler over the msg arrived through the pubsub channel


r = redis.Redis(...)
p = r.pubsub()
p.psubscribe(**{'cmdchannels*': hnd})
thread = p.run_in_thread(sleep_time=0.001)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文