If you have gone through Part I of this series, you will now have a bit of an idea of what redis is and its simple but awesome power. This part explains how redis can act as a publish - subscribe medium. In simpler terms- Notifications: the simplest of things that makes coding so much easier! This series will conclude with Part III: Creating a chat system with Redis in VB.NET.
As with its predecessor, this tutorial is going to be simple and direct. I can show you what powers you, not how to use them :D. One of the most powerful features of redis is its PubSub mode. In other words, when something happens, anything that wants to know it will be informed. This tutorial will show you the fundamental way to use this. My next tutorial will show how to develop a complete chat application (twitter/Facebook) in VB.NET. I know that mostly applications like that are developed in the web platform, but for the purpose of these tutorials, I am going to use it anyway.
Using the Code
The prerequisites are the same as from part I. You can use the same project or build a new one.
Here, we'll have a single application that can be run in 2 modes:
- As a Subscriber
- As a Publisher
I've built the project in such a way that this is toggled by a menu at startup. You may use it as different applications too! Run the EXE more than once to use it...
Public Class SubscriptionMessageEventArgs
Public Property Key As String
Public Property value As String
To subscribe to an array of channels, call the
Subscribe function. To publish to a channel, call the
Publish function. As you may see, a client that subscribes cannot do anything else. We deal with this situation in the next tutorial, unless of course you figure out the simple solution for it on your own!
Well, that's it for the second part of the tutorial. Do ask and comment if you have any queries.
- 1st May, 2011: Initial version