Publication subscriptions for Redis

Source: Internet
Author: User

What is it:

A message communication pattern between processes: the sender (pub) sends a message, and the Subscriber (sub) receives the message.

Subscribe/Publish a message map

Before you can receive a message after you have subscribed

1. You can subscribe to multiple, SUBSCRIBE C1 c2 C3

2. News release, PUBLISH C2 Hello-redis

Subscribe First

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
1) "Message"

Release

127.0.0.1:6379> PUBLISH C2 Hello-redis
(integer) 1
127.0.0.1:6379> PUBLISH C1 hello1122
(integer) 1
127.0.0.1:6379>

Receive Message

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
1) "Message"
2) "C2"
3) "Hello-redis"
1) "Message"
2) "C1"
3) "hello1122"

======================

3. Subscribe to multiple, wildcard *,psubscribe new*

4. Receive the message, PUBLISH New1 redis2015

127.0.0.1:6379> Psubscribe new*
Reading messages ... (Press Ctrl-c to quit)
1) "Psubscribe"
2) "new*"
3) (integer) 1
1) "Pmessage"
2) "new*"
3) "New1"
4) "redis2015"
1) "Pmessage"
2) "new*"
3) "New2"
4) "redis2016"

127.0.0.1:6379> PUBLISH New1 redis2015
(integer) 1
127.0.0.1:6379> PUBLISH new2 redis2016
(integer) 1
127.0.0.1:6379>

Publication subscriptions for Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.