In the second blog post series “Redis for .NET Developer” I will show how we will use C# to connect to Redis.
We will be using StackExchange.Redis library to connect to Redis. One can download StackExchange. Redis through NuGet.

StackExchange.Redis is a high performance general purpose redis client for .NET languages (C# etc).

1. Let’s Download our Nuget package, one can use the command line like below or use Visual Studio (I am using VS2015).

Search for redis in your nuget window.

Nuget Redis

Nuget Redis

Once installed you will see in your output windows.

Nuget Redis Result

Nuget Redis Result

Now that the nuget package is installed, we can build a C# console app that will connect to your redis server.
Below is a sample code to connect to localhost of your redis.

The above code will allow you to connect to Redis and store a string key “testKey” with a value of “testValue”.

For better modulation of Redis it is recommended to store ConnectionMultiplexer as a static singleton in your application.

Below is example of a RedisStore that stores the ConnectionMultiplexer as a static Lazy loaded singleton.

Now our previous code would something like

In my next blog post I will cover the data structures that Redis provides.

For code please visit https://github.com/taswar/RedisForNetDevelopers

For previous Redis topics

  1. Intro to Redis for .NET Developers