发布于 2015-06-22 08:58:13 | 367 次阅读 | 评论: 0 | 来源: 网络整理

Redis 的 pub sub实现了邮件系统,发送者(在 Redis 术语中被称为发布者)发送的邮件,而接收器(用户)接收它们。由该消息传送的链路被称为信道。

Redis客户端可以订阅任何数目的通道。

例子

以下举例说明如何发布用户的概念工作。在下面的例子给出一个客户端订阅一个通道名为redisChat


redis 127.0.0.1:6379> SUBSCRIBE redisChat

Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "redisChat"
3) (integer) 1

现在,两个客户端都发布在同一个通道名redisChat消息及以上的订阅客户端接收消息。


redis 127.0.0.1:6379> PUBLISH redisChat "Redis is a great caching technique"

(integer) 1

redis 127.0.0.1:6379> PUBLISH redisChat "Learn redis by tutorials point"

(integer) 1


1) "message"
2) "redisChat"
3) "Redis is a great caching technique"
1) "message"
2) "redisChat"
3) "Learn redis by tutorials point"

Redis PubSub 命令

如下表所示相关Redis PubSub的一些基本的命令:

S.N. Command & 描述
1 PSUBSCRIBE pattern [pattern ...] 
订阅通道匹配给定的模式。
2 PUBSUB subcommand [argument [argument ...]] 
讲述了PubSub的系统,例如它的客户是活动在服务器上的状态。
3 PUBLISH channel message 
发布一条消息到通道。
4 PUNSUBSCRIBE [pattern [pattern ...]] 
停止监听发布到通道匹配给定模式的消息。
5 SUBSCRIBE channel [channel ...] 
监听发布到指定的通道信息。
6 UNSUBSCRIBE [channel [channel ...]] 
停止监听发布给定的通道信息。
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务