2-redis Pub/sub Publish a subscription

Source: Internet
Author: User

1 basic

Publish/Subscribe is a message communication pattern. Instead of publishing messages to subscribers, publishers publish to different channels. Subscribers accept messages of the channel they are interested in and do not need to contact the publisher.

Sub/pub are both client, and channel is server.

, the message is sent to the three sub client when the new message is posted to Channel1 via the Publish command.

2 commands

Subscribe to a channel on the CLI: Channel1

127.0.0.1:6379> SUBSCRIBE channel1reading Messages ... (Press Ctrl-c to quit) 1) "Subscribe" 2) "Channel1" 3) (integer) 1

In another CLI, publish messages to Channel1 via the Publish command

127.0.0.1:6379> PUBLISH channel1 1 (integer) 1127.0.0.1:6379> PUBLISH channel1 ' good ' (integer) 1

Already received on sub

127.0.0.1:6379> SUBSCRIBE channel1reading Messages ... (Press Ctrl-c to quit) 1) "Subscribe" 2) "Channel1" 3) (integer) one) "message" 2) "Channel1" 3) "1" 1) "message" 2) "Channel1" 3) "Good"

2-redis Pub/sub Publish a subscription

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.