PITS Blog
  • Home
  • Services
    • Dedicated team Have your own development team at our location in Kerala, India. We tailor our employees individually to your project.
    • Website & web shop Get into the online business and sell your products around the clock. Or convince yourself with a modern website on desktop and mobile devices.
    • Application development We develop very individual web or software applications for you for a wide variety of needs.
    • Hybrid or native iOS & Android Apps Online business is often done on the go today, and the trend is rising. Invest now and make your software mobile-compatible.
  • Credentials
  • Technology
  • Process
  • About us
  • Contact
  • White papers
  • Jobs
  • Blog
  • Startups
�
Avatar

Azure Redis Cache

By Nishanth A on November, 22 2016
demo post

By Visakh R N

WordPress and .NET

By Priyanka K

Roadmap to become a DevOps Engineer

By Francis Varghese

Gutenberg - More Than Just An Editor

By Priyanka K

Azure Redis Cache is based on the popular open-source Redis cache.  It gives you access to a secure, dedicated Redis cache, managed by Microsoft and accessible from any application within Azure.

Features

  • Redis is an advanced key-value store, where keys can contain data structures such as strings, hashes, lists, sets and sorted sets. Redis supports a set of atomic operations on these data types.
  • Redis also supports trivial-to-setup master-subordinate replication, with very fast non-blocking first synchronisation, auto-reconnection on net split and so forth.
  • Updating cache values without having to retrieve the item from the cache.
  • Other features include transactions, publish/subscribe, Lua scripting, keys with a limited time to live and configuration settings to make Redis behave like a cache.
  • Azure Redis Cache uses Redis authentication and also supports SSL connections to Redis.

Azure Redis Cache is available in the following tiers:

  • Basic—Single node, multiple sizes, ideal for development/test and non-critical workloads. The basic tier has no SLA.
  • Standard—A replicated cache in a two node Primary/Secondary configuration managed by Microsoft, with a high availability SLA.
  • Premium—The new Premium tier includes a high availability SLA and all the Standard-tier features and more, such as better performance over Basic or Standard-tier Caches, bigger workloads, disaster recovery and enhanced security.

Additional features include:

  • Redis persistence allows you to persist data stored in Redis cache. You can also take snapshots and back up the data which you can load in case of a failure.
  • Redis cluster automatically shards data across multiple Redis nodes, so you can create workloads of bigger memory sizes (greater than 53 GB) and get better performance.
  • Azure Virtual Network (VNET) deployment provides enhanced security and isolation for your Azure Redis Cache, as well as subnets, access control policies and other features to further restrict access.

Create a Redis Cache using the Azure Management portal

In the Azure Management portal you can create a Redis Cache by selecting Redis Cache-> Create   as shown in Figure1

RC1
Figure1

Next you will need to first select a name (DNS name) that is unique. The resource group your cache will belong to, and the location. You should strive to select a location that is in the same region as the services that will use the cache for best performance. The DNS name for your cache will be {cache name}.redis.cache.windows.net.

RC2
Figure 2

After the cache is created you will need two pieces of information from the Redis Cache blade to start using the cache in your code: the host name and an access key. You can access both of these in the Redis Cache blade as shown in Figure3

RC3
Figure3

 

Using Azure Redis

Storing Session State in Azure Redis    

Sometimes your web application requires state but cookies aren’t sufficient for your needs. Session state provides a server managed state mechanism that can help meet an application’s needs for storing state. Microsoft has provided a way to easily integrate Azure Redis Cache with shared session in .Net applications.

First, you’ll need to install the required Nuget packages into your project. Click on “Manage Nuget Packages” in your project and search for RedisSessionStateProvider. You should see Microsoft.Web.RedisSessionStateProvider by Microsoft. Click on that one and install it. Next you’ll need to configure the applications shared session state to use the Azure Redis Cache you have created. To do this you’ll need to modify the sessionState portion of the Web.config.

RC4

Once you have the config done, you’re ready to start utilizing the cache as normal. An example controller is shown below: 

RC5 

A few notes about using Azure Redis Cache for Session State:

  • Data types must be serializable
  • Make sure to remove the InProc session state provider if you were using that before from the Web.config

Storing Html Output Cache in Azure Redis

The output cache is a great way to improve your sites performance by storing html in a cache to reduce response times and load for your site. Microsoft has also provided a way to easily configure your .Net application to use Azure Redis Cache for an Html output cache.

The first step is to add the Nuget package to your project. Click on “Manage Nuget Packages” in your project and search for RedisOutputCacheProvider. You should see Microsoft.Web.RedisOutputCacheProvider by Microsoft. Click on that one and install it. Next is to configure the output cache to use the Azure Redis Cache by altering the caching section in the Web.config. 

RC6

Now you can start defining what you want to store in the output cache. You can do this in the controller or in a view. You can simply specify a controller action result to store in the output cache by adding the OutputCache attribute to the action method.

RC7

You can also specify in the view by doing 

RC8

This very simple code will store the pages in the cache for the specified amount of time. You can also configure the cache to vary by headers, parameters, etc.

Custom use of the Azure Redis Cache

To configure the Azure Redis Cache for general use, simply install the StackExchange.Redis by Stack Exchange Nuget package. Once installed, you can connect and interact with the cache easily. Below is a sample controller which utilizes a connection to the cache to increment a value. That value is also retrieved and displayed on a different view utilizing the same connection property.

RC9

References

https://azure.microsoft.com

We'd love to hear from you.

Contact us

Switzerland
thomas(at)pitsolutions(dot)com
+41 (0) 43 558 4360

India
enquiries(at)pitsolutions(dot)com
+91 (0) 471 270 0615 / 715

UAE
mohammed(at)pitsolutions(dot)com
+971 (0) 4 359 8610

USA
arnab(at)pitsolutions(dot)com
+1 (0) 703 945 8076

Copyright © 2019PIT Solutions AG.An ISO 9001:2015 certified company. All Rights Reserved

SCROLL TO TOP