Have you ever needed to calculate the view count for a certain file? Or number of requests for a single page? Or update a User balance either add or deduct?
You may have to store them in a Database or keep them in memory and risk losing them when the system is rebooted. Now comes in-memory caching solutions that saves efforts and guarantee data persistence, and one of the most known solution is Redis.
So, what is Redis?
Redis (REmote DIctionary Server) is an open-source software used for caching data in memory, and no need to fear losing data since Redis guarantees data persistency.
- Speed and durability.
- Ease to install and use.
- Key-Value based caching system.
- Support for multiple data models or types like Lists, Sets, HyperLogLogs, Hash tables, etc..
- Ability to withstand multiple concurrent write requests or transactions per second, via a technique known as sharding.
- No strict rules pertaining to defining strict schemas or tables for data (schemaless).
- Support multiple languages like C, C++, C#, Perl, Python, R, Ruby, Java, Erlang and many others.
Who uses Redis?
Redis is used by many of large and leading companies in IT like Github, Pinterest, Snapchat, StackOverFlow, Craigslist, etc.
Small application on Redis
The example is written in C# language and StackExchange.Redis package. After installing Redis it listens on port 6379 which is the default.
First we will demonstrate some basic and useful command like KEYS to list available keys as picture No.1
To add a new key, use SET command as in picture No.2
To retrieve a value, we use GET command as in picture No.3
Now we use C# to do the same command as before
In summary, Redis offers highly performant and efficient read and write.
We touched on basic Redis commands in this article and how to use them in our application. Instructions to do so using C# has been mentioned earlier.
Want to get the source code? here
I can recommend.