In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the use of the double-linked list in Redis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
In the list list in the Redis data type, the common commands for adding and deleting data are lpush,rpush,lpop,rpop, where l is on the left and r is on the right. You can add and delete operations on the left and right sides, indicating that this is a two-way data structure, and the list data structure is a two-way linked list, similar to the LinekdList linked list in java.
Linked list provides efficient node rearrangement ability and sequential node access. It modifies the data of linked list by modifying the pre and next pointers of nodes.
The C language does not have a built-in linked list data structure, so Redis builds its own linked list structure.
Linked list data structure, linked list and linked list nodes
A linked list consists of linked lists and linked list nodes, each of which is represented by an adlist.h/listNode structure:
Typedef struct listNode {/ / Front node struct listNode * prev; / / Post node struct listNode * next; / / Node value void * value;} listNode
Multiple listNode can form a double linked list through prev and next pointers, as shown in the question:
Multiple listNode can form linked lists, but for ease of management, adlist.h/list is used to manage linked lists. The list structure is as follows:
Typedef struct list {/ / list header node listNode * head; / / list footer structure listNode * tail; / / Node value copy function void * (* dup) (void * ptr); / / Node value release function void (* free) (void * ptr); / / Node value comparison function int (* match) (void * ptr, void * key) / / number of nodes in the list unsigned long len;} list
The list structure provides the header pointer head, the footer pointer tail, and the node count len for the linked list. The following figure shows a linked list of list structures and three listNode nodes:
The characteristics of the Redis linked list implementation are summarized as follows:
Bidirectional: the linked list node has prev and next pointers, through which each data can be obtained.
Quickly calculate the length of the linked list: calculate the length of the list through the len attribute in the list structure, and the time complexity is O (1)
Polymorphisms: linked list nodes use void* pointers to save nodes, so linked lists support saving different types of values
Application of double linked list
List keys, publish subscriptions, slow queries, monitors, etc.
Thank you for reading this article carefully. I hope the article "what is the use of double-linked lists in Redis" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.