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