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

What are the application scenarios of redis caching

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

Share

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

What are the application scenarios of redis caching? Perhaps many people do not understand, in order to let you understand better, the editor summed up the following content, I hope you can gain something according to this article.

The contradiction between large-scale reading and writing data and database reading and writing ability

Briefly review the development of CPU cache, in order to solve the huge difference between the computing speed of CPU and the read speed of memory, CPU uses cache to store instructions and data.

Cache from the initial motherboard cache to the current level 3 cache, the cache size is also increasing. Data from the network show that the hit rate of the CPU cache is about 80%.

By comparing the contradiction between CPU and memory in the process of computer development, we can find that the contradiction between large-scale reading and writing data and database reading and writing ability in large-scale websites is similar. We can also build a faster storage area between the database and the application-cache.

We are most familiar with Redis as a cache. We know that the author of Redis designed Redis because when he used a relational database, no matter how optimized, the performance could not meet his expectations, so he wrote an in-memory database by hand.

In the case of caching, we have the following application scenario:

1. Hot spot data for example, we can save the SQL query results in memory, or we can save the pictures that users often view in memory.

two。 The ranking is based on the data structure of zset provided by Redis, which makes it easier to implement the ranking. The relevant contents of the ranking can be compared with the design and implementation of the ranking algorithm. In the case of small-scale data, using Mysql to achieve ranking is not much of a problem, but once the amount of data has been increased, then continuous Mysql reading and writing will become a bottleneck.

3. One of the application scenarios of counter / speed limiter counter is to count the number of likes of users, and one of the application scenarios of speed limiter is to limit the number of visits of users'ip. The reason why Redis can be used for counters is that Redis is single-threaded, and each time the previous instruction must be executed before the next instruction. This ensures that multiple instructions are not executed at the same time; that is, concurrency problems do not occur. The principle of speed limiter is similar.

4. By using the intersection operation sinter of Set data structure provided by Redis, common friends can find the intersection of two Set sets more easily, while the query of connected tables using database will cause a lot of performance overhead, because there are a large number of users on large websites.

5. The publish / subscribe provided by simple message queuing Redis is an extremely simple messaging system. Unlike Kafka, it provides the ability to divide into different topic and different partitions and provide persistence. Redis's message queuing is used in scenarios that do not require high reliability.

6. The session shared Session is used to record who the user is. When the application is deployed in a cluster mode, we need a place to uniformly manage the session. We can use the database to record the session, but at this time, the performance of the database is high, and the session is usually timely. We need to implement this logic in the code, but if we use Redis to share session, then there will not be such a problem.

Many of the above application scenarios can also use other technologies to solve problems, but technologies such as Redis will be a better solution under certain resource constraints.

After reading the above, do you have any further understanding of the application scenario of redis caching? If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.

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