Redis is an in-memory data structure store, used as database, cache and message broker. At first it seems a bit hard to get on with Redis so I tried with MemCache, Ignite Cache but once I get on with Redis since then I am not using anything else for caching. Redis is super fast compared with other caching alternatives.
We can install redis as windows service. This is out of scope for this article so I am providing some external references so that you can get started with, how you can install Redis as windows service.
http://www.alternatestack.com/development/running-redis-server-on-windows/
http://www.saltwebsites.com/2012/how-run-redis-service-under-windows
Once you are done with Redis installation, a bit hectic though as compared with any other Microsoft products, where we are habitat of using "Next" and get our desired product installed. But the efforts worth it, trust me!!!
You can read more on this here, https://stackexchange.github.io/StackExchange.Redis/
That's it now lets go ahead with code,
How we read from Redis?
It's a bit tricky to install and configure Redis but once you are through it, it's an amazing speed booster for your application.
We can install redis as windows service. This is out of scope for this article so I am providing some external references so that you can get started with, how you can install Redis as windows service.
http://www.alternatestack.com/development/running-redis-server-on-windows/
http://www.saltwebsites.com/2012/how-run-redis-service-under-windows
Once you are done with Redis installation, a bit hectic though as compared with any other Microsoft products, where we are habitat of using "Next" and get our desired product installed. But the efforts worth it, trust me!!!
We need to find for a package,stackexchange.redis, refer below screen,
This will add all the required dependencies to get you started with Redis. StackExchange.Redis is a high performance general purpose redis client for .NET languages.You can read more on this here, https://stackexchange.github.io/StackExchange.Redis/
That's it now lets go ahead with code,
using StackExchange.Redis; //add this namespace
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
db.KeyDelete("CorrectionInRate"); //This is to delete cache data using key
db.StringSet("CorrectionInRate", formData); //formData is the data which I want to store in cache, it can be anything, string/ List
How we read from Redis?
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
string cacheData = db.StringGet( "CorrectionInRate");
if (cacheData != null)
ViewBag.CacheData = cacheData;
It's a bit tricky to install and configure Redis but once you are through it, it's an amazing speed booster for your application.
Comments
Post a Comment