So far we have covered a bit of ground in learning how to configure both Redis Sentinel and Redis Cluster for production. Now that we have an understanding of the server, and a running setup, its time to start digging into using Redis.

It would be rather tedious and redundant to start going through all the various Redis Data types and regurgitating what is already in the documentation.

Instead, its time to start writing some code. For this, I’ll be using C# and StackExchange.Redis as my library. I’ll be using visual studio (b/c I’m addicted to Resharper) but you can just as easily install VSCode to follow along.

As far as I can tell there are going to be a couple of, rather generic, use cases .

  • A backend application, maybe a windows service, or docker container.
  • A website

If you’re creating a website, and you’re using IIS, you may want to persist session state to Redis so as to make load balancing a snap. Thats pretty simple with the AspNet Redis Session State Provider.

So that will be our first example.

To get started you’ll want to create a new website project, here is what I selected in VS:

Next install the package

Or from Visual Studio:

Now when we open up our web.config we can see that some entries have been added, one is an example of all the configs and is commented out, the other is the actual entry:

Using the example comment as a guide, update the entry labeled “MySessionStateStore” to point to your redis server. If you have followed along with the previous tutorials, or if this is running in production, you’ll probably have multiple redis servers. You can input a valid Connection String based upon the specification in the StackExchange.Redis library.

So something like this as the connection string

Frankly this example is a bit antiquated. Most of us these days will be using a more modern web framework, such as MVC or WebAPI.

We’ll move onto another web example where we actually write some code next time.