Introduction
In this blog, I explain how to implement Azure Redis cache step by step into your new MVC application or existing MVC application
Implementing Azure Redis Cache To MVC Application
- Azure Redis Cache in Azure Portal
Step 1 - Create Azure Redis Cache in Azure Portal
To use Azure Redis Cache Log into your Azure portal with your UserId and Password. Once you are logged in it will forward you to the Dashboard.
From the Search menu, search for Database in the Portal as shown below.
Once you select the Database option, under that you can search for Redis Cache as shown in the below picture.
Select the Redis Cache and create a new Redis Cache in the Portal.
While creating Redis cache on the basis of Pricing tier, you will find 3 options,
- Basic – Single node. Multiple sizes up to 53 GB.
- Standard – Two-node Primary/Replica. Multiple sizes up to 53 GB. 99.9% SLA.
- Premium – Two-node Primary/Replica with up to 10 shards. Multiple sizes from 6 GB to 530 GB. All Standard tier features and more including support for Redis cluster, Redis persistence, and Azure Virtual Network. 99.9% SLA.
Here I have shown the Premium One with Redis Cluster in the below image.
Once you create your Cache just pin it to the Dashboard so that it will be easy to work on it. So in this way you are able to create a Redis Cache in the Azure Portal.
Step 2 - First, we need to install one NuGet package (reference) in our project
Now go to the Azure Portal and check the access key for the Redis Cache
Comment your session state and put in this code.
- <sessionState mode="Custom" customProvider="RedisSessionProvider">
- <providers>
- <add name="RedisSessionProvider" type="Microsoft.Web.Redis.RedisSessionStateProvider" port="your port" host="yourhostname" accessKey="your access key" ssl="true" />
- </providers>
- </sessionState>
Conclustion
So in this blog, I explain how to implement Redis cache into your project using a web.config file with Azure
and also, you can check your Azure portal to see if this cache is working or not.