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

Introduction of redis ordered set command

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article is to share with you about the introduction of redis ordered assembly commands, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Redis ordered collections, like collections, are collections of elements of type string, and duplicate members are not allowed.

The difference is that each element is associated with a score of type double. Redis sorts the members of the collection from small to large by scores.

The members of an ordered set are unique, but the score can be repeated.

The collection is implemented through a hash table, so the complexity of adding, deleting, and finding is all O (1). The maximum number of members in the collection is 4294967295 (each collection can store more than 4 billion members).

The realization method of ordered set command

Command ziplist Encoding implementation method zset Encoding implementation method ZADD calls the ziplistInsert function, inserts the member and the score as two nodes into the compressed list, first calls the zslInsert function, adds the new element to the jump table, and then calls the dictAdd function to associate the new element to the dictionary ZCARD calls the ziplistLen function to get the number of nodes contained in the compressed list Divide this number by 2 to get the number of set elements, access the length attribute of the jump table data structure, directly access the number of collection elements ZCOUND traverses the compressed list, the number of nodes with statistical scores in a given range traverses the jump table, and the number of nodes with statistical scores in a given range ZRANGE traverses the compressed list from header to footer, returning all elements in the given index range to traverse the jump table from header to footer Returns all elements in a given index range ZREVRANGE table traverses the compressed list to the header, returns all elements in the given index range traversing the jump table from the footer to the header, returns all elements in the given index range ZRANK traverses the compressed list from header to footer, finds a given member, records the number of nodes along the way, when a given member is found The number of nodes along the way is the ranking of the elements corresponding to the member traversing the jump table from header to footer, looking for a given member, and recording the number of nodes along the way. When a given member is found, the number of nodes along the way is the ranking of the element corresponding to that member. ZREVRANK traverses the compressed list from the footer to the header, finds a given member, records the number of nodes along the way, when a given member is found. The number of nodes along the way is the ranking of the elements corresponding to the member traversing the jump table from the tail to the header, looking for a given member, recording the number of nodes along the way, when a given member is found, the number of nodes along the way is the ranking ZREM of the corresponding element of the member, traversing the compressed list, deleting all nodes containing the given member, and the score node next to the deleted member traverses the jump table Deletes all jump table nodes that contain a given member. And unassociate the members and scores of the deleted element in the dictionary, ZSCORE traverses the compressed list to find the node that contains the given member, and then takes out the element score saved by the score node next to the member node to extract the score of the given member directly from the dictionary. The above is the introduction of the redis ordered collection command. Xiaobian believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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