Redis
Introduction to Redis
Basic definition
Redis is an open-source tool that runs as a service in the background that allows us to store data in memory for high-performance data retrieval and storage purpose.
According to the official documentation
Redis
is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps etc. Two of the most popular usages of redis are building a caching layer or act as a session storage system.
Why Redis?
Example:1.
Imagine you got a web application that may be running directly on a server somewhere or maybe on any container such as docker; Let's suppose that web-application needs to retrieve some data from a database which is placed somewhere else in the form of MySQL or NoSQL. A query for data retrieval may take some 30-sec to 60-sec time to run. For any user who is trying to fetch some data, so waiting for such a long time is not a really great user experience.
Won't be better if the user gets their required data from the server within 5-sec to 10-sec or in less, depending upon how large the dataset is. This is where Redis cache comes into the picture, so what we can do is instead of directly querying a database, we can actually store data inside of a Redis caches instance and make the retrieval of that data occur directly from memory / RAM from a server that's running the Redis service. Instead of the web application has to go all the way back to the database server, instead, the web server can check with Redis to see if it has the data that it wants and if not, then the Redis caches can be populated with data from the original database.
Example:2.
Imagine our app deals with users who are authorized to take different actions within our app. Each time we authenticated a user, we want to derive their authorization for controlling access in your app.
We might consider sending the full list of authorisations to the user and having them send it to you with each action as proof of authorization. There is nothing wrong, cryptographically, with this approach, however, if users of our app has more than a couple of authorizations, this becomes very hard to scale, but there is another option we should contemplate.
Instead of sending the list of authorizations to the user, what if we store our users’ authorizations in some form of database and proved the user a unique key (token) that they must send us as proof of authorization? We can then use the key to look up the user’s authorization when they make a request. This of course doesn’t stop us sending the user a copy of their authorizations periodically for building our apps UI, but we have made our authorisation system much more scalable.
Who uses Redis?
More than 5000 companies are using Redis in their tech stack. According to the official documentation of redis following are some popular companies that are using redis:
- Twitter,
- GitHub,
- StackOverflow,
- Snapchat, etc
Redis Advantages
The following are some advantages of using redis:
- It’s very fast.
- It has flexible data structures such as strings, hashes, lists, sets, etc.
- Redis uses its own hashing mechanism called Redis Hashing.
- Redis is an NoSQL Database.
- It is easy to setup and easy to use.
- One very important advantage of redis is that it is open source and stable.
Disadvantages of redis
Everything has some pros and cons, so the following are some limitations of redis:
- Redis is not a query language, so there is no support for relational algebra.
- one of the major disadvantages of redis is it becomes expensive over time and you need to keep a close watch on the usage.
Some best document on Redis :
Author ~ Anish Kumar