Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Column name or number of supplied values does not match table definition when dealing with temp tablesStupid me #2 - Where is my SSIS package executed? »
    comments

    Introduction

    So I thought I needed redis to do some much needed caching for an app I am writting. And I was right, as I often am.

    So I installed redis and used the .net redis client from the always brilliant Demis Bellot.

    Redis is a key-value database, a dictionary on steroids. It is great for caching. And it is fast at what it does by keeping most things in memory.

    Redis

    First I used the windows version of redis and that even worked, but it is not production ready. So I decided to install a linux VM with redis on it.

    I downloaded mint 14 and did apt-get install redis-server. Then you need to change the file in /etc/res/redis.conf and comment the line bind 127.0.0.1 or change it to bind 0.0.0.0.

    I used VMWare workstation 8 and I had to use NAT translation for the network and add forward the 6379 port.

    you can check if your redis server works by doing redis-cli ping on the server. This should return PONG. To be sure the binding works you should try redis-cli -h ipaddress ping. where you change ipaddress with the ip-address of the linux machine. This should also give PONG.

    You can now do the same on the host to check if you can connect.

    If all works well you can start writing to your redis server. And we might do some reading to.

    Redis-client

    Here is our model.

    1. Public Class Mandate
    2.         Public Property Id As String
    3.         Public Property Version As Integer
    4.         Public Property Name As String
    5.     End Class

    Firstly you need to nuget servicestack.redis.

    The following code writes some entries to our redis server.

    1. Using redisClient = New RedisClient(ipaddressofthelinuxvm)
    2.             Dim client = redisClient.As(Of Mandate)()
    3.             client.GetAllKeys().Count.PrintDump()
    4.             For i As Integer = 1 To 500
    5.                 client.SetEntry(i, New Mandate() With {.Id = i, .Version = 1, .Name = "Name" & i})
    6.             Next
    7.             Dim mandate5 = client.GetValue(5)
    8.             mandate5.Version += 1
    9.             client.SetEntry(5, mandate5)
    10.             client.GetValue(5).PrintDump()
    11.             client.GetAllKeys().Where(Function(x) Not x.Contains("ids")).Count.PrintDump()
    12.             client.Save()
    13.         End Using
    14.         Console.ReadLine()

    If you run the above you will get.

    0
    {
    Id: 5,
    Version: 2,
    Name: Name5
    }
    500

    On a second run you will get.

    501
    {
    Id: 5,
    Version: 2,
    Name: Name5
    }
    500

    So I add 500 objects but it tells me I have 501. The 501st is the id of the mandate class.

    I don't really need to do the save, since redis will do an autosave every so often (depends on your redis.conf).

    Conclusion

    It is here that I pretend that redis is easy to use and to set up. And it is, just not for me ;-).

    I would like to thank Demis for setting me on the way to solving my connectivity problems with the VM.

    The second time it won't add another 500 entries, it will update the ones that are there.

    About the Author

    User bio imageChris is awesome.
    Social SitingsTwitterHomePageLTD RSS Feed
    redis, vb.net
    InstapaperVote on HN

    No feedback yet

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)