Redis Deep Data structures

Source: Internet
Author: User
Tags rehash

Redis Primary Data structure

Linked list

The C language used by Redis does not have such a data structure built in, so Redis builds its own linked list implementation. One of the underlying implementations of the list key is the linked list, which includes more than one element, and the list contains elements that are longer strings, and Redis uses the list key as the underlying implementation.

In addition to the linked list key. The redisserver itself also uses a linked list to hold state information for multiple clients. Use a linked list to build the client output buffer.

eg:redis> Llen integers

(integer) 1024

The integers list key includes a total of 1024 integers from 1 to 1024, and the underlying implementation of the integers list key is a linked table, with each node in the linked list holding an integer value.

Each linked list node is represented by a listnode structure, and each node has a pointer to the predecessor and back nodes. The linked list implementation of Redis is a double-ended linked list.

Each linked list is represented by a list structure with a header node pointer, a footer node pointer, and a chain table length.

Because the predecessor node of the list header node and the back node of the footer node all point to NULL, the list implementation of Redis is a chain-free list.

Dictionary

Dictionary. Symbol table or map, an abstract data structure that holds key-value pairs

Redis has built its own dictionary. The dictionary uses a hash table as the underlying implementation, with each dictionary with two hash tables. One is used in peacetime, and one is used only when the rehash is in progress. A hash table can have multiple hash table nodes. Each hash table node saves a key-value pair in the dictionary. Redis uses the MURMURHASH2 algorithm to calculate the hash value of a key.

Two or more of the keys are assigned to the same index of the hash table array. These keys have clashed. The Redis hash table uses the chain address method to resolve key conflicts.

As the operation continues to run, the key-value pairs that the hash table holds will gradually increase or decrease. In order to keep the load factor of the hash table within a reasonable range, the work of extending and shrinking the hash table can be done by running the rehash (again Hash) operation, which will need to rehash all the key-value pairs included in the existing hash table into the new hash table. And the rehash process is not a one-time finish, but a gradual completion.

Jumping table

A jump table is an ordered data structure that maintains multiple pointers to other nodes in each node. So as to achieve the purpose of high-speed access to nodes.

Redis>zrange Fruit-price 0 2 withscores

Fruit-price all the data of the ordered collection are saved in a jumping table, each jumping table node has saved a fruit price information, all fruits by the price of high and low from the lowest level in the Jumping table in order.

Redis uses jumping tables as one of the underlying implementations of an ordered set key, assuming that an ordered set consists of more elements. Or when an element member in an ordered collection is a longer string. Redis uses a jumping table as the underlying implementation of an ordered set key. Redis uses a jump meter in just two places. One is to implement an ordered set key. There is also an internal data structure used in the cluster node.

Redis's jump table implementation consists of zskiplist and zskiplistnode two structures, in which zskiplist is used to hold the information of the jumping table (such as the table Head node, footer node, length). The Zskiplistnode is used to represent the jumping table node.

Integer collection

An integer collection is one of the underlying implementations of a collection key, and when a collection consists of only an integer value element, and the number of elements in the collection is not long, Redis uses an integer set as the underlying implementation of the collection key.

Redis > Sadd Numbers 1 3 5 7 9

A compressed list is a sequential data structure developed to conserve memory.

Redis>rpush 1st 1 3 5 10086 "Hello" "World"

A compressed list is a sequential data structure consisting of a series of specially coded contiguous blocks of memory.

The compression list is used as one of the underlying implementations of the list key and hash keys

A compressed list can include multiple nodes. Each node can hold an array of bytes or integer values.

Add a new node to the compression list, or remove the node from the compressed list. Cascading update operations may be triggered, but the chances of such an operation appearing are not high.

Redis Deep Data structures

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.