Posts

Showing posts from January, 2017

Redis Hash Datatype for .NET developers

Redis Hash Datatype are similar to Dictionary in C#. Redis Hash datatype is a mapping of key as string and value as a string. Redis hashes are memory optimized. var hashKey = “hashKey” ;    HashEntry [ ] redisMerchantDetails = {      new HashEntry ( “Name” , “Ravindra Naik” ) ,      new HashEntry ( “Age” , 26 ) ,      new HashEntry ( “Profession” , “Software Engineer” )    } ;    redis . HashSet ( hashKey , redisMerchantDetails ) ;    if ( redis . HashExists ( hashKey , “Age” ) )    {      var age = redis . HashGet ( hashKey , “Age” ) ; //Age is 26    }    var allHash = redis . HashGetAll ( hashKey ) ;    //get all the items    foreach ( var item in allHash )    {      //output      //key: Name, value: Ravindra Naik      //key: Age , value: 26      //key: Profession, value: Software Engineer      Console . WriteLine ( string . Format ( “key : {0}, value : {1}” , item . Name , item . Value ) ) ;    }    //get all t

Why Redis?

Why Redis? Redis is an open source, in-memory data structure store, used as database, cache and message broker. It also provides high performance and low latency, simplicity while developing complex functionality and compatibility with a wide variety of systems and languages. It is blazingly fast and is written in C and is completely in-memory and is optimized to handle millions of operations in a second with less than 1 ms latency in a single server. It also gives in pre-built data structures for database operations which include: Lists, sets, sorted sets, hashes, hyperloglogs, bitmaps and geospatial indexes. It has client libraries in almost every language and active developer community and contributors. Best cases to use Redis would include Real-time analytics, High-speed transactions, High-speed data ingest, messaging queues, session storage, in-app social functionality, application job management, geo search and caching. Redis is also rated as the fastest growing database sinc

Using Radis Hashes .NET

Redis Hashes are essentially maps between string fields and string values. Here I have published on how to get started using Redis with .NET . Once you have installed StackExchange.Redis and have setup console script as per above link, here are the things to do for using Redis Hashes with .NET. Create a new visual studio console project. Then right click select on Manage Nu-Get packages and select online option and search for “StackExchange” in the search field and install  StackExchange.Redis . Now to get connected to Redis and its database here is a snippet.   // This should be stored and reused var redis = ConnectionMultiplexer.Connect(“localhost”); // IDatabase is simple object which is cheap to build IDatabase db = redis.GetDatabase(); Lets create a data object.           var readObject = new ReadObject(); readObject._id = “3”; readObject.Name =”Ravi”; readObject.Age = “26”; readObject.Address = “Bangalore, India”; Now lets convert this object into Hash entry list.