Home > Article > Backend Development > How does a non-relational database help our web project and where can it be used?
I have a question now: What is the use of non-relational databases such as redis or memercach in our web programs? Where can it be used?
I have a question now: What is the use of non-relational databases such as redis or memercach in our web programs? Where can it be used?
https://www.zhihu.com/question/20059632
https://www.zhihu.com/question/20304711
It can be used when caching. If users use the cache when browsing our website, they no longer need to query the database. The data directly from the cache can reduce the pressure on the server database and keep the software and hardware running healthily. There are many places where it is used, I just give an example^_^
First of all, I have never heard of memercach, only memcache
1. Since non-relational databases are key-value, queries will be very fast. Relational databases support transactions and can support multi-table associations.
2.Redis and Memcache are both key-value storage systems. They are all memory-based databases. Of course, some databases can be flushed to the hard disk. Generally speaking, they are mostly used for caching. Of course, there are many other application scenarios, such as redis can be used as a queue.
This is my personal understanding. We can distinguish databases from two perspectives: one is the storage medium (hard disk, memory); the other is the storage model, that is, the way to express and operate the data you save, similar to the file system to the hard disk.
Back to the main question, first of all, from the perspective of storage model, relational database is based on sets and relational algebra. Each table is a set. For table addition, deletion, modification and query, corresponding selection, union, It should be said that relational algebra operations such as intersection and connection are relatively comprehensive and rigorous, whether it is derivation at the mathematical level or testing of corporate informatization practices over the years. But at the same time, it also has limitations. For example, when you want to store an employee information, this employee information may have many attributes, such as position, rank, departments at all levels, transfer records, etc.; if you use a relational database, it will Multiple attribute tables and relationship tables will be created, and you can also use mongodb to store it, simply put it in a JSON data (PS: if it is just a query). Therefore, from this perspective, NOSQL represents a special storage model that can usually store certain types of data more simply. To give an example in life, you can imagine a relational database as a standard storage box, and NOSQL as a special container, such as a fishing rod bucket.
Secondly, from the storage media, memory-based databases like memcached/redis are usually used as caches to store commonly used data or sessions;
Finally, due to this optimization of NOSQL, it often appears in big data situations. This is also easy to understand. If the amount of data is small, the original relational database is enough. Therefore, many NOSQL are designed with clusters in mind, such as mongodb. You can easily configure a replica set (supporting read-write separation) and configure sharding.
The above are all conceptual things. If the subject needs to know more, I think there are two ways:
1. Search the Internet for sharing of excellent practices of XX database and see in what scenarios the industry uses NoSQL, for example:
http://sanwen8.cn/p/1a7xFmh.html
2 , look at the introduction of NOSQL cloud service, which usually comes with typical application scenarios of this database, such as:
https://www.aliyun.com/product/kvstore?spm=5176.7960203.237031.34.78OO9N
When frequent updates are required and the data patterns are different, a Philippine relational database is used.
For example, there is a function to send Weibo. Some Weibo may have pictures, and some may be plain text. How about using mysql to save here? Use text to store the formatted json, or two fields.
The first method is not conducive to searching, and the second method will cause a waste of storage space