Azure Redis - Part 1

In this article am going to review step by step Redis capabilities and go over some C# libraries to code for an application to be used on Azure Redis Service .
So if you want to build an application and looking for  a NoSQL database that supports High performance , Low latency and Fully managed by a cloud service please continue reading this article .
Redis is a fast Key-value NoSQL database , ranked #1 among other Key-value databases (db-engines.com) , Redis is an in-memory data structure store, used as database, cache and message broker . Redis is mainly used as a cache database but it can also be used as the primary database as it also supports 'Durability'.

Redis Is Awesome - Get Started

you can skip this part if you are already familiar with Redis
Lets talk about some of the great features of Redis , Redis supports different types of data types such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries , the only limitation of Redis is your RAM capacity , so as long as you have enough resources of RAMs available on your machine Redis will be working well fast enough for you .

Redis supports transactions , concurrency and durability but it does not support foreign-keys .
it support most of the programming languages including c# which we are going to talk about it more on this article check all supporting languages here .

And the last but not the least The replication method of Redis is Master-Slave with Sharding , and we are going to talk about Azure cloud service supporting Redis so you can feel free to code and leave other resource and distribution managements to Azure .

Can i run Redis on windows ?  yes check it out here .
how much data does Redis occupy on your RAM ? i have to personally say its amazingly well enough to store 1Milion record for 100-250Mb on your RAM .
what if your RAM stops working? Redis has a built in on-disk persistence , and you can define policies to store your data on disk when different events triggers like when you insert a data to the database.

Start Coding 

Here we are going to talk about a popular C# client of Redis - StackExchange.Redis - this package is developed by Stack Exchange so take a look and check their Github and install  it via their NugetPackage  . these packages communicate with redis by redis special commands check all commands here.
This library leverages most of Redis features and you can use them in your application , BUT , how about serializing and deserializing you data (your models C# classes) , for that i recommend you to use StackExchagne.Redis.Extensions   which gives some serialization options for your data here we are adding Newtonsoft as an example :

var serializer = new NewtonsoftSerializer();
var cacheClient = new StackExchangeRedisCacheClient(serializer);


now with 'cacheClient' you can access redis commands.
we are not going through these nuget packages on this post (part 1) . but make sure to check their wiki and add it to your project to go to next step.

Azure Redis 

Now that we are ready to use Redis , we need a server to host our database , as i said before if you are going to use redis on your local computer and start a single node you can download the executable files here.

Azure Redis is a cloud service to manage your Redis database distribution , It gives you access to a secure, dedicated Redis cache, managed by Microsoft and accessible from any application within Azure.

Azure Redis is available in different pricing tiers , and if you pay for the whole package your Redis service will support Replication , secure access , data persist ency ,backup and snapshots in case of a failure ,and it automatically shards data across multiple Redis nodes. to create your service In the Microsoft Azure portal, click New > Data and Storage > Redis Cache.
Azure also gives you some reports and insights by monitoring your available nodes .



While you use Redis on Azure you may face some performance issues which are mostly addressed and solved on this article , so make sure to read this when you deployed your application and created your Azure redis service.
But the most important thing to consider is the way you build the connection channel to redis, when you want to create a Redis connection in your client application and here is the most recommended method :

private static Lazy lazyConnection = new Lazy(() => { return
ConnectionMultiplexer.Connect("cachename.redis.cache.windows.net,ssl=true,abortConnect=false,password=password"); });


Also consider that Redis is auto configured on azure and you can not use some of the costume configurations on your Redis connection .

If you start using Basic , Standard pricing Tier of Azure Redis and your Azure Redis stops responding (for any reason like when RAM is filled up) you either  need to contact support to reset your service or change your pricing tier to a premium one . 

Comments

Popular posts from this blog

Xamarin Forms , Designer Tools

How To Run Xamarin Forms Previewer Beta On Windows

Google Firebase - Easy Steps To Run Your Chrome Notification Service