What is Redis?
Hello, today we will be talking about Redis. Redis is a NoSql Database.
what is that mean?
It’s mean Redis is not a relational database, Instead it works with key-value principle. We create a key which will be the primary identifier to access our value and with that key we will be accessing our value.
We’ve just explained what a NoSQL database is. Now, let’s dive into the main reasons why we use Redis. Redis has various use cases, ranging from in-memory caching to serving as a message bus and addressing certain security concerns. However, one of its most preferred use cases is caching.
What is caching, what does it do exactly?
it’s holding the data in user’s local web browser. If you are asking but why we are doing that I will be giving a nice example for this question.
Let’s say we have a platform like a social media or E-commerce if we have one user that’s okay the sysem will work nice in most cases but what if we have millions of users then the system may be overwhelmed and busy with too many user. And getting the data and responsing to user every time and doing that with going and using to our database and services will make the system too busy. That’s why we are using caching to hold the data in user’s local memorage and it will be returning the user’s data without go and make the system busy. For example if we have a List of product we can create a key with Redis and make the key “productList”, we can hold all products data as our value. And that’s how after getting the data one time from the database and caching it. When the user will need it we will be able to use it again and again without use and make busy our services.
Redis data types:
Redis have various data types. Not just one but we will only be talking abour 3 of them, these are: String, Set, and Hash.
String: The string data type is more individualistic. We can create more than one string but every value will have it’s own key and these key will not be related to each-other. As seen in the picture we have a key and if we want to add a new Platform then we will be creating a new key too and it will not be related with the other one. we can access the data with the key.
Set: The Set data type is like a series of strings. We can add new values using the same key, and when we query the key, it returns all the data associated with it. The difference between Set and String is that in String, we can change the old data using the key, but we cannot add another data to the same key. In Set, we can hold multiple data entries of the same type under one key.
As you see in the photo we have a commandSet key and we can have more than one member and if we want to delete just one of them we can do that.
Hash: Hashes are more like databases because each time, there’s a new key and value under the same Hash table key. In the image, under the “hashPlatform” key, we are holding Fields and values. With Field keys, we can access each value that has been mapped with the Field.
When we want to access we can use the hash’s key and field to each value you can check the code from the photo.
If you want to see a project to check and try to understand how to use it in a project I have already created. you can check from here.
I am learning a lot while I am writing I hope you learned a lot too while you are reading and enjoyed it. Don’t forget to follow on Medium to keep going to learn together. See you soon :)