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

Redis is suitable for scene summary at eight points.

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

Share

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

What scenarios is redis suitable for?

1. Caching

Caching is now a must-kill for almost all large and medium-sized websites. Reasonable use of caching can not only improve the speed of website access, but also greatly reduce the pressure on the database. Redis provides key expiration function and flexible key elimination strategy, so Redis is now widely used in caching.

2. Ranking list

Many websites have ranking applications, such as JD.com 's monthly sales list, goods on the new list according to time, and so on. The ordered set data class construction provided by Redis can realize a variety of complex ranking applications.

3. Counter

What is a counter, such as the number of views of goods on e-commerce websites, the number of videos played on video websites, and so on. In order to ensure the real-time efficiency of the data, you have to give + 1 to each browse, and it is undoubtedly a challenge and pressure to request the database operation every time when the concurrency is high. Redis provides incr commands to achieve counter function, memory operation, very good performance, very suitable for these counting scenarios.

4. Distributed session

In cluster mode, when there are few applications, it can be satisfied by using the session replication feature of the container. When there are more complex applications, session services centered on Redis and other in-memory databases are generally built. Session is no longer managed by containers, but by session services and in-memory databases.

5. Distributed lock

Distributed technology is used in many Internet companies, and the technical challenge brought by distributed technology is the concurrent access to the same resource, such as global ID, inventory reduction, second kill and so on. Scenarios with small concurrency can be realized by pessimistic and optimistic locks of the database, but in the case of high concurrency, it is not ideal to use database locks to control the concurrent access of resources, which greatly affects the performance of the database. You can use the setnx function of Redis to write distributed locks. If the setting returns 1, it means that the lock was acquired successfully, otherwise the lock failed, and there are more details to be considered in the practical application.

6. Social network

Like, step on, follow / be followed, mutual friends and so on are the basic functions of social networking sites. The visit volume of social networking sites is usually large, and the traditional relational database type is not suitable for storing this type of data. The data structures such as hash and collection provided by Redis can easily achieve these functions.

7. Latest list

Redis list structure, LPUSH can insert a content ID in the list header as a keyword, LTRIM can be used to limit the number of lists, so that the list is always N ID, no need to query the latest list, just go to the corresponding content page according to ID.

8. Message system

Message queuing is a necessary middleware for large websites, such as ActiveMQ, RabbitMQ, Kafka and other popular message queuing middleware, which is mainly used for business decoupling, traffic peaking and low real-time asynchronous processing. Redis provides publish / subscribe and blocking queue functions to implement a simple message queuing system. In addition, this cannot be compared with professional messaging middleware.

The above are the eight suitable scenes sorted out by the editor. Thank you for your reading and support.

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