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 is the structure of big data in Redis 5

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

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what is Redis 5 big data structure". In daily operation, I believe many people have doubts about what Redis 5 big data structure is. Xiaobian consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the question of "what is Redis 5 big data structure"! Next, please follow the small series to learn together!

I. Character string

String type is the most basic data structure of redis. First of all, the key is string type, and several other structures are built on the basis of string type, so string type can be the learning basis of other four data structures. String types can actually be strings (simple strings, complex strings (xml, json), numbers (integers, floating-point numbers), binary (pictures, audio, video)), but not more than 512M.

Use scenario:

Cache function: The most classic use scenario of strings, redis is the most cache layer, Mysql as the storage layer, most of the request data is obtained from redis, because redis has high concurrency characteristics, so cache can usually play a role in accelerating reading and writing and reducing back-end pressure. (Why redis has the characteristics to support high concurrency, explained in the next article).

Counters: many applications use redis as a basic tool for counting, which can achieve fast counting, query cache functions, and data can be dropped to other data sources in one step. For example, the video playback count system uses redis as the basic component of video playback count.

Shared session: For the sake of Load Balancer, distributed services will balance the access of user information to different servers. Users may need to log in again after refreshing an access. To avoid this problem, you can use redis to centrally manage user sessions. In this mode, as long as the high availability and scalability of redis are guaranteed, each time you obtain user update or query login information, you will directly obtain it from redis.

Speed limit: For security reasons, let the user input the mobile phone Captcha every time you log in. In order to prevent frequent access to the SMS interface, the frequency of obtaining the Captcha per minute will be limited.

II. Hash

In redis, hash type refers to the key itself and a key-value pair structure, such as value={{field1,value1},...... fieldN,valueN}}

Usage scenarios: Hash structures are more intuitive than string serialization cache information and are easier to update. Therefore, it is often used for user information management, but the hash type and relational database are different, the hash type is sparse, and the relational database is completely structured, the relational database can do complex relational queries, and redis to simulate relational complex queries, difficult to develop, high maintenance costs.

III. LIST

List type is used to store multiple ordered strings. Each string in the list becomes an element. A list can store up to 2 to the 32nd power-1 elements. In redis, you can insert (pubsh) and pop (pop) at both ends of the queue table. You can also obtain a list of elements in a specified range, obtain elements in a table under a specified index, etc. List is a relatively flexible data structure. It can act as a stack and queue. There are many application scenarios in actual development.

Advantages:

The elements of a list are ordered, which means that a list of elements within a certain range can be retrieved by index subscripts.

The elements in the list can be repeated.

Usage scenario:

Message queue: redis lpush+brpop command combination can realize blocking queue, producer client uses lupsh to insert elements from the left side of the list, multiple consumer clients use brpop command to block "grab" elements at the end of the list, multiple clients ensure consumption Load Balancer and high availability clipboard.png Message queue model ↑

Article list: Each user has his own article list, now need to page display article list, at this time you can consider the use of lists, the list is not only orderly, but also support elements according to the index range.

IV. Collections

Set types are also used to store elements of multiple strings, but unlike lists, duplicate elements are not allowed in sets, and elements in sets are disordered, and elements cannot be obtained through index subscripts. In addition to supporting additions, deletions, and queries within sets, redis also supports intersection, union, and difference sets of multiple sets, and reasonably uses set types to solve many practical problems in actual development.

Usage scenario:

Tag: The typical usage scenario of the collection type, such as one user is interested in entertainment and sports, and the other may be interested in news. These interests are tags. With these data, you can get people with the same tag and tags of users 'common hobbies. These data are important for user experience and user viscosity. (Relationship maintenance between users and tags should be performed in one thing to prevent data inconsistency caused by partial command failure)

V. Ordered collection

Ordered sets are related to sets in that they retain the property that sets cannot have duplicate members, but differ in that the elements of ordered sets can be sorted, but they differ from lists in that they use index subscripts as sorting criteria, and they assign a score to each element as sorting criteria. (Elements in an ordered set cannot be repeated, but cstores can be repeated, just like students in a class cannot be repeated, but test scores can be the same).

At this point, the study of "What is Redis 5 Big Data Structure" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

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

Wechat

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

12
Report