Redis Publish subscription model

Source: Internet
Author: User

Redis Subscribers:

Redis 127.0.0.1:6379> SUBSCRIBE Redischat

Reading messages ... (Press Ctrl-c to quit)

1) "Subscribe"

2) "Redischat"

3) (integer) 1


Now, two clients are published in the same channel name Redischat message and above the subscribing client receives the message.


Redis Publishing Side

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"



Post-release messages are received by multiple subscribers at the same time



Principle:

The redisserver contains two important structures:

1. Channels: is actually a KEY-VALUE map structure, key is the Subscriber channel, value is the client's list

2. Patterns: List of storage mode +client addresses


Find the clients-list that match the channel in the publish from the Pubsub_channels, and then go to Pubsub_patterns to find each matching pattern and client. Send a publish message to these clients.


When the program terminates or the instance of the class is destroyed, the Subscriber instance is logged off, otherwise the subscriber is always present in the Redis.


This article is from the "DBSpace" blog, so be sure to keep this source http://dbspace.blog.51cto.com/6873717/1868995

Redis Publish subscription model

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.