Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » VB.NET » General » Downloads
 
Add your own
alternative version
Go to top

Redis Tutorial Part II: Using Redis as a Pub/Sub Medium

, 2 May 2011
Create a simple redis pub/sub client pair in VB.NET
redisPart02_demo.zip
Debug
RedisExample02.exe
RedisExample02.vshost.exe
RedisExample02.vshost.exe.manifest
ServiceStack.dll
ServiceStack.Interfaces.dll
ServiceStack.ServiceInterface.dll
redisPart02_src.zip
RedisExample02
RedisExample01
bin
Debug
RedisExample02.exe
RedisExample02.vshost.exe
RedisExample02.vshost.exe.manifest
ServiceStack.dll
ServiceStack.Interfaces.dll
ServiceStack.ServiceInterface.dll
ext-dll
ServiceStack.dll
ServiceStack.Interfaces.dll
ServiceStack.ServiceInterface.dll
ServiceStack.ServiceInterface.pdb
My Project
Application.myapp
Settings.settings
RedisExample02.vbproj.user
RedisExample01.suo
RedisExample02.suo
Module MainModule

    Private MyRedisStore As RedisStore

    Sub Main()
        MyRedisStore = New RedisStore(True)
        AddHandler MyRedisStore.OnSubscriptionMessage, AddressOf SubcribedMessageReceived
        Select Case ChooseOption()
            Case 1
                RunAsSubscriber()
            Case 2
                RunAsPublisher()
            Case Else
                EndMe()
        End Select
    End Sub

    Private Sub RunAsPublisher()
        Dim Stopped As Boolean = False
        Do While Not Stopped
            Console.Write("Write the message [Type Exit to stop]: ")
            Dim Message As String = Console.ReadLine()
            If Message.ToLower = "exit" Then
                Stopped = True
            Else
                MyRedisStore.Publish(AChannel, Message)
            End If
        Loop
    End Sub

    Private Sub SubcribedMessageReceived(ByVal sender As Object, ByVal e As SubscriptionMessageEventArgs)
        Console.WriteLine("Received Message on channel {0} -> {1}", e.Key, e.value)
    End Sub

    Private AChannel As String = "aKey:UserInput"
    Private Sub RunAsSubscriber()
        Console.WriteLine("Now Listening for messages....")
        MyRedisStore.Subscribe(AChannel)
    End Sub

    Private Function ChooseOption() As Integer
        Console.WriteLine("=============== MENU ===================")
        Console.WriteLine("   Any other number, exits the program..")
        Console.WriteLine("1. Start as subscriber")
        Console.WriteLine("2. Start as publisher")
        Console.WriteLine("--------------------------")
        Console.Write("Choose :")
        Dim Userinput As String = Console.ReadLine()
        Return If(IsNumeric(Userinput), Userinput, -1)
    End Function

    Private Sub EndMe()
        Console.Write("Press any key to exit...")
        Console.ReadKey()
        End
    End Sub

End Module

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Hariharan Arunachalam
Student
India India
Hariharan leapt into the field of programming after being introduced to C in his second year at college. A fan of basketball and chess, the logical thought process behind programming and the concepts of linking real principles onto a concrete platform pushed him deep into this field. On finishing his bachelor's majoring in Electrical and Electronics engineering with Soft Computing, Numerical Analysis and Biomedical Engineering as minor, he did a six month stint at India's second largest IT company- Infosys Technologies. He left Infosys armed with strong concepts of SDL Cycles and process development, gained domain knowledge in Java and had explored Visual basic, C++, C# and kept his mind open for more. Currently working in a startup as the product designer, his arsenal of technologies has doubled to accommodate the challenges his job demands.
Off work, he enjoys learning new languages (non-programming) and is currently teaching himself German and Spanish. He also enjoys travelling around and exploring new ideas, places and relationships.
 
Currently attempting to extend his education to post graduation.
Follow on   Twitter

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 2 May 2011
Article Copyright 2011 by Hariharan Arunachalam
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid