Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to do mysql cache with redis

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to do mysql cache with redis. I hope I can add and update some knowledge to you. If you have any other questions you need to know, you can continue to follow my updated articles in industry information.

In practical projects, the MySQL database cloud server is sometimes located on another host and needs to access the database through the network. Even if the application is on the same host as the MySQL database, accessing MySQL also involves disk IO operation (MySQL also has some data pre-read technology, which can reduce disk IO read and write. Further research in this part).

In short, reading data directly from MySQL is not as efficient as reading data directly from memory. In order to improve the efficiency of database access, people use a variety of methods, one of which is to use a memory-given cache system to place between the database and the application.

When looking for data, first look it up in memory, if found, use it, if not, then actually access the database. This method can improve the overall efficiency of the system in some scenarios (for example, frequently finding the same data).

Using the redis nosql database as the cache of the Mysql database, when looking for it, first look for the redis cache and return the result if it is found; if it is not found in the redis, then look for the Mysql database, and the flowers found return the results and update the redis; if it is not found, return empty.

In the case of writing, it is written directly to the mysql database, and the mysql database automatically updates the changed contents to redis through triggers and UDF mechanisms.

Block diagram:

Read steps:

1. Client reads redis, returns the result if it is hit, and goes to 2. 0 if it is not hit.

2. Client reads the database and returns null if it is not found in the database; if it is found in the database, the result is returned and the Redis is updated.

Write steps:

1. Client modifies / deletes or adds data to MySQL.

2. The trigger of MySQL calls the user-defined UDF.

3. UDF updates the modified / deleted or added data to redis.

These are the details of how redis does mysql caching, please pay attention to other related articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report