Trying Out Redis via NuGet

Friday, May 10, 2013

From the Redis home page:

Redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

Redis is also fast. Incredibly fast. Mind-numbing fast.

For more information, try the Redis docs or “The Little Redis Book” by Karl  Seguin.

MSOpenTech just released a NuGet package of their Windows port to make it easy to download Redis and try the server from the command line. Combine this package with the ServiceStack.Redis package and it easy to be up and running quickly.

install-package redis-64
install-package servicestack.redis

The redis-64 package (for 64 bit systems) doesn’t add assembly references to a project, but does drop the Redis server executable in the packages\Redis-64.{version}\tools directory of the solution. Opening a command window and running redis-server.exe will launch the server with the default settings.

Here is a quick C# program to store and retrieve an object using the ServiceStack client:

static void Main(string[] args)
{
    var client = new RedisClient("localhost");
    var patientClient = client.As<Patient>();

    var patient = new Patient
        {
            Name = "Scott", 
            Codes = new List<string> {"1.1", "2.2"}
        };
    patient.Id = patientClient.GetNextSequence();
    patientClient.Store(patient);

    var retrievedPatient = patientClient.GetById(patient.Id);
    Console.WriteLine("{0}:{1}", retrievedPatient.Id, retrievedPatient.Name);

}

Once the program runs, you can also go to the command line client in the tools directory (redis-cli.exe), and verify the data stored inside of Redis. Here is a shot of the cli client and server running:

Redis running from NuGet


Comments
gravatar Francisco Oliveira Sunday, May 12, 2013
Hi Scott! Your thumb wasn't generated correctly. http://odetocode.com/images2/Windows-Live-Writer/Trying-Out-New-Redis-NuGet-Packages_13462/redis_thumb.png Cheers,
gravatar Dan Wednesday, May 22, 2013
Pretty cool! Did you end up doing anything interesting with Redis? I'm curious as to what situations people find this useful out in the wild.
gravatar Scott Allen Saturday, May 25, 2013
@Dan: Not yet, going to try it out as a read/write cache shortly.
gravatar evertonw Saturday, May 25, 2013
Hi, Was this complete Csharp program? When I use csc.exe complains about. Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1 Copyright (C) Microsoft Corporation. All rights reserved. odetocode.cs(18,35): error CS0246: The type or namespace name 'Patient' could not be found (are you missing a using directi or an assembly reference?) odetocode.cs(20,23): error CS0246: The type or namespace name 'Patient' could not be found (are you missing a using directi or an assembly reference?) odetocode.cs(23,25): error CS0246: The type or namespace name 'List' could not be found (are you missing a using directive an assembly reference?) odetocode.cs(23,38): error CS1925: Cannot initialize object of type 'List#string#' with a collection initializer Regards
gravatar Scott Saturday, May 25, 2013
@evertonw: This was just a code snippet. You'd have to define a Patient class and also include the proper namespaces to get that exact code to compile.
Comments are closed.

My Pluralsight Courses

K.Scott Allen OdeToCode by K. Scott Allen
What JavaScript Developers Should Know About ECMAScript 2015
The Podcast!