Redis is an in-memory cache database;
The data model is: key - value, the format used by non-relational databases to store data;
Database cache:(Recommended learning:Redis video tutorial)
The key value of the sql statement, the query result resultSet is the value, when When accessing the same query statement (select * from t_product), as long as it has been queried before, the call cache will directly return the resultSet, saving the time of the database reading disk data.
Persistence layer cache:
Reduces the time to connect to the database; reduces the process of encapsulating resultSet into an object.
Caching of business layer and control layer:
Reduce the call level.
Describe the logic of caching in the business layer:
Query product information
Judge whether the current query has data in the cache
If If there is data, return directly and the current request ends;
If there is no data, query the persistence layer database data, obtain the data storage and cache it for subsequent access;
More Redis related technologies Article, please visit theIntroduction to Using Redis Database Tutorialcolumn to learn!
The above is the detailed content of Why redis is suitable for caching. For more information, please follow other related articles on the PHP Chinese website!