This post is mainly about the publishment and subscription in Redis.I think you may subscribe some offiial
accounts on wechat,and when the authors published something new to their accounts,you will get them in
your wechat.The instance can make you understand this pattern easily.You will find there only 6 commands
for publishment and subscription.
This post introduces the basic usages as well.I will show you how to publish a message to a channel.publish
is the command to publish sometings.I publish a channel named news-nba with the message nba.And the client
return me a integer 0.What is the meaning of the return value?It means that there is nobody subscribe this channel.
I open a new client for subscriber.In this client,I subscribe the above channel news-nba.It will return something
about this channel.
OK,let's publish a new message to the news-nba to see the changes in the both clients.After publishing lakers to
the news-nba channel,this client returns 1.It means that the channel has a subscriber.
Let's turn to the subscriber's client.You will find the message lakers was already in the client.so amazing it is.
publish a new message to the news-nba,it returns 2 meaning ...(you understand it)
All right,let's see the other commands of this feature in Redis.Seeing the sql first:
channels channelname To execute this sql,you will get all of the channel whoes
name start with news.Redis can also
The subscriber's client will receive the message from the channel news-tech.
Again!!Publishing a message to a new channel.
As you can see,the client receives this message as well.
following code demonstrates the usage in C#.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。