The difference between mysql relational database and redis non-relational database

The difference between mysql and redis

1. The database types of mysql and redis.
Mysql is a relational database. It is mainly used to store persistent data. It stores data on the hard disk and has a slow reading speed.
Redis is a NOSQL, which is a non-relational database and a cache database. It stores data in the cache. The cache read speed is fast, which can greatly improve the operating efficiency, but the storage time is limited. 2. The operating mechanism of mysql mysql as a
persistent
storage The relative weakness of relational databases is that every time a request is made to access the database, there are I/O operations. If the database is accessed repeatedly and frequently. First: it will take a lot of time to repeatedly connect to the database, resulting in too slow operating efficiency; second: repeated access to the database will also cause the database load to be too high, so the concept of caching is derived at this time.
3. Cache
The cache is the buffer (cache) for data exchange. When the browser performs a request, it will first search the cache. If it exists, it will get it; otherwise, it will access the database.
The benefit of caching is fast reading speed
4. redis database
The redis database is a cache database used to store frequently used data, thus reducing the number of database accesses and improving operating efficiency.
5. Summary of the differences between redis and mysql
(1) In terms of type
, mysql is a relational database and redis is a cache database
(2) In terms of function,
mysql is used to store data persistently on the hard disk. It is powerful but relatively fast. Slow
redis is used to store frequently used data in the cache, with fast reading speed.
(3) In terms of requirements
, mysql and redis are generally used together due to different requirements.
Replenish:
Redis and mysql should be selected according to specific business scenarios.
Mysql: The data is placed on the disk. Redis: The data is placed in the memory.
Redis is suitable for storing some frequently used and relatively hot data. Because it is placed in the memory, the read and write speeds are very fast. Generally It will be used in the following scenarios
: ranking list, counter, message queue push, friend following, fans

First of all, you must know that mysql is stored in the disk and redis is stored in the memory. Redis can be used for both persistent storage and caching. At present, most companies' storage is mysql + redis, with mysql as the primary storage and redis as the auxiliary storage. Storage is used as a cache to speed up access and read and improve performance
. So why not just use redis to store everything?
My opinion is: because redis is stored in memory, if it is stored in memory, the storage capacity must be much less than that of a disk. If you want to store a large amount of data, you can only spend more money to buy memory, resulting in some applications that do not require high Performance is relatively wasteful, so currently it is basically mysql (primary) + redis (auxiliary). Redis is used where performance is needed, and mysql is used where high performance is not required. Good steel is used on the blade.

1. Mysql supports sql query, which can realize some related queries and statistics;
2. Redis has relatively high memory requirements, and all data cannot be placed in redis under limited conditions;
3. Mysql prefers to store data, and redis prefers Fetching data quickly, but redis is not as good as mysql when querying complex table relationships, so you can put popular data in redis and mysql stores basic data.

Supongo que te gusta

Origin blog.csdn.net/m0_57207884/article/details/119669673
Recomendado
Clasificación