Redisメッセージ購読パブリケーション


Redisメッセージ購読パブリケーション
一、何ですか
プロセス間のメッセージ通信モード:送信者(pub)はメッセージを送信し、サブスクライバ(sub)はメッセージを受信する.
二、命令
シーケンス番号
コマンド#コマンド#
説明
1
PSUBSCRIBE pattern [pattern …]
指定されたモードに一致する1つ以上のチャネルを購読する
2
PUBSUB subcommand [argument [argument …]]
サブスクリプションとパブリッシュシステムのステータスの表示
3
PUBLISH channel message
指定したチャンネルにメッセージを送信
4
PUNSUBSCRIBE [pattern [pattern …]]
指定されたすべてのモードのチャンネルをキャンセル
5
SUBSCRIBE channel [channel …]
指定された1つ以上のチャンネルの情報を購読する
6
UNSUBSCRIBE [channel [channel …]]
所定のチャンネルをキャンセルすることを指す
三、ケース
メッセージを受信するには、購読してからパブリッシュします.
1複数一括購読可能、SUBSCRIBE c 1 c 2 c 3
2メッセージリリース、PUBLISH c 2 hello-redis
3複数購読、ワイルドカード*、PSUBScriBE new*
4メッセージを受け取り、PUBLISH new 1 redis 2015
クライアントA
127.0.0.1:6379> SUBSCRIBE c1 c2 c3
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "c1"
3) (integer) 1
1) "subscribe"
2) "c2"
3) (integer) 2
1) "subscribe"
2) "c3"
3) (integer) 3

クライアントB
127.0.0.1:6379> PUBLISH c2 hello-redis
(integer) 1
127.0.0.1:6379> PUBLISH c1 hello1122
(integer) 1

クライアントAはメッセージを受信する
1) "message"
2) "c2"
3) "hello-redis"
1) "message"
2) "c1"
3) "hello1122"

クライアントC
127.0.0.1:6379> PSUBSCRIBE new*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "new*"
3) (integer) 1

クライアントD
127.0.0.1:6379> PUBLISH new1 redis2015
(integer) 1
127.0.0.1:6379> PUBLISH new13 redisnews2016
(integer) 1

クライアントCはメッセージを受信する
1) "pmessage"
2) "new*"
3) "new1"
4) "redis2015"
1) "pmessage"
2) "new*"
3) "new13"
4) "redisnews2016"