gpt4 book ai didi

redis - 通俗地说,什么是 Redis Pub/Sub?

转载 作者:IT王子 更新时间:2023-10-29 05:54:50 25 4
gpt4 key购买 nike

我为什么要使用它?举一些非常基本的例子。

最佳答案

Redis 客户端订阅 以接收标有特定标签(称为 channel )的消息。其他客户端发布到这个 channel 。每当任何人向 channel 发布消息时,Redis 都会通知每个订阅客户端。

您还可以订阅 channel 模式 - 考虑正则表达式匹配。

这有助于使代码可分发。它允许代码块在不同的进程中运行,甚至可能在不同的机器中运行,并通过这些队列相互通信。

此功能来自repeated user requests .给出了一个示例用例 here :

a news-related site needs to update the cached copy of its home page every time that a new article is published.

The background cache worker process subscribes to all channels that begin with ‘new.article.’:

redis> PSUBSCRIBE new.article.*

The article publishing process creates a new technology article (in this example, this article has ID ‘1021’), adds the article’s ID to the set of all technology articles, and publishes the article’s ID to the ‘new.article.technology’ channel:

redis> MULTI
OK
redis> SET article.technology.1021 "In today's technology news, ..."
QUEUED
redis> SADD article.technology 1021
QUEUED
redis> PUBLISH new.article.technology 1021
QUEUED
redis> EXEC
1. OK
2. (integer) 1
3. (integer) 1

At this point, the background cache worker process will receive a message and know immediately that a new technology article was published, subsequently executing the appropriate callback to re-generate the home page.

http://redis.io/topics/pubsub

关于redis - 通俗地说,什么是 Redis Pub/Sub?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5786276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com