Redis Introduction

I’ve recently spent a little time working with Redis, which is a key-value store NoSQL database. Redis (REmote DIctionary Server) is an in-memory database, but the data can also be persisted to disk.
With a key-value store, you submit a record with a unique string key, and store a value for that key. In Redis the value can be Strings, Lists, Sets, Hashes or Ordered Sets. A record is retrieved by the key, there aren’t joins like there would be in a relational database.
There isn’t an official Redis download for Windows, but I was able to download it using Chocolatey, which installed it as a Windows service.
Next I downloaded a C# client, I opted for Sider. The Sider page also includes some sample code, with more sample code available as part of the repository code.
Below is some sample code where I instantiate the Client, save some values, update a value and delete a value before exiting.

using System;

using Sider;

namespace RedisDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create client
            RedisClient client = new RedisClient("localhost", 6379);

            // Set values
            client.Set("QB", "Matt Ryan");
            client.Set("HeadCoach", "Mike Smith");
            client.Set("Owner", "Arthur Blank");
            client.Set("RB", "Michael Turner");
            client.Set("DE", "John Abraham");

            // Display Values
            Console.WriteLine("QB = " + client.Get("QB"));
            Console.WriteLine("Head Coach = " + client.Get("HeadCoach"));
            Console.WriteLine("Owner = " + client.Get("Owner"));
            Console.WriteLine("RB = " + client.Get("RB"));
            Console.WriteLine("DE = " + client.Get("DE"));

            // Set a new Running Back
            client.Set("RB", "Steven Jackson");
            Console.WriteLine("New RB = " + client.Get("RB"));

            // Remove player record
            client.Del("DE");
            Console.WriteLine("Removed DE");

            // Close connection
            client.Dispose();

            Console.WriteLine("Press any key to Exit");
            Console.ReadLine();
        }
    }
}
Advertisements

One Response to Redis Introduction

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: