Click here to Skip to main content
11,492,691 members (58,319 online)
Click here to Skip to main content
Articles » Database » NoSQL » General » Downloads
Add your own
alternative version

Redis VB.NET Part I: Introduction to Using Redis (NoSQL) with .NET

, 29 Apr 2011 CPOL 21.5K 10.7K 12
Create a usable redis component to enable usage of the redis storage system
RedisExample01_demo.zip
Debug
RedisExample01.exe
RedisExample01.vshost.exe
ServiceStack.dll
ServiceStack.Interfaces.dll
ServiceStack.ServiceInterface.dll
RedisExample01_src.zip
RedisExample01
RedisExample01
bin
Debug
RedisExample01.exe
RedisExample01.vshost.exe
ServiceStack.dll
ServiceStack.Interfaces.dll
ServiceStack.ServiceInterface.dll
RedisExample01_Demo.zip
Release
ext-dll
ServiceStack.dll
ServiceStack.Interfaces.dll
ServiceStack.ServiceInterface.dll
ServiceStack.ServiceInterface.pdb
My Project
Application.myapp
Settings.settings
RedisExample01.vbproj.user
RedisExample01.suo
Imports ServiceStack.Redis
''' <summary>
''' The redis store encapsulation class around the ServiceStack redis client 
''' </summary>
''' <remarks>This class is cumulatively constructed across the tutorial and is not broken.</remarks>
Public Class RedisStore

#Region " Properties "

    Private _sourceClient As RedisClient
    Public ReadOnly Property SourceClient() As RedisClient
        Get
            Return _sourceClient
        End Get
    End Property

#End Region

#Region " Constructors "

    Public Sub New()
        MyClass.New(False)
    End Sub

    Public Sub New(ByVal ForceCheckServer As Boolean)
        _sourceClient = New RedisClient
        If ForceCheckServer AndAlso Not IsServerAlive() Then
            Throw New Exception("The server has not been started!")
        End If
    End Sub

#End Region

    Public Function IsServerAlive() As Boolean
        Try
            Return SourceClient.Ping
        Catch ex As Exception
            Return False
        End Try
    End Function

#Region " Functionalities "

#Region " Get/Set Keys "

    Public Function SetKey(ByVal key As String, ByVal value As String) As Boolean
        Return SourceClient.Set(key, value)
    End Function

    Public Function SetKey(Of T)(ByVal key As String, ByVal value As T) As Boolean
        Return SourceClient.Set(Of T)(key, value)
    End Function

    Public Function GetKey(ByVal key As String) As String
        Return Helper.GetString(SourceClient.Get(key))
    End Function

    Public Function GetKey(Of T)(ByVal key As String) As T
        Return SourceClient.Get(Of T)(key)
    End Function

#End Region

#End Region

End Class

Public Class Helper

    Private Shared ReadOnly UTF8EncObj As New System.Text.UTF8Encoding()

    Public Shared Function GetBytes(ByVal source As Object) As Byte()
        Return UTF8EncObj.GetBytes(source)
    End Function

    Public Shared Function GetString(ByVal sourceBytes As Byte()) As String
        Return UTF8EncObj.GetString(sourceBytes)
    End Function

End Class

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 | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 29 Apr 2011
Article Copyright 2011 by Hariharan Arunachalam
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid