
In this article, I will demonstrate how to use Redis Cache service provided by Microsoft Azure. First part is about how to setup the Redis Cache from Azure. In the second part, I'll be showing you on how to setup and access the cache by using Visual Studio with C#. We will see how to determine whether or not you need to upgrade the Redis Cache in the last part.
How to setup the Redis Cache from Azure?
Then select "Data + Storage", a list of data storage related services will be shown on the right.
For the pricing tier list options, the minimum is C0 Basic Plan with 250 MB cache and up to 256 connections. You can select this to do the test. Or you can click on "View All" link to see all available plans. Finally, click on the "Create" button.
How to setup and access the Azure Redis cache by using Visual Studio with C#?
I'll be using Visual Studio program with C# to do the demo project. I create a new project with ASP.NET Web Application template with .NET Framework 4.5, which I named it, DemoRedisCache. In the project, I created 3 folders: Common, Managers, Services for a general multi-tier architecture.
<appSettings>
<add key="CacheEndpoint" value="yourDNSname.redis.cache.windows.net" />
<add key="CachePassword" value="yourRedisCachePassword_here" />
<add key="CacheSyncTimeout" value="3000" />
<add key="CacheConnectTimeout" value="4000" />
</appSettings>
-- Fruit.cs
public class Fruit
{
public int FruitID { get; set; }
public string FruitName { get; set; }
public string Color { get; set; }
}
-- RedisCache.cs
In the Services folder, I have one file.
-- CacheService.cs
In the Managers folder, I have one file.
-- CacheManager.cs
In the root, I have a start up webpage that I use it to demo the cache.
-- TestCache.Page.aspx
It will look like this when app runs.