[Redis] zset data structure

A description

redis one of the data structure zset (sorted set- ordered set), and its main role to achieve rankings for, you can get ranked a few to a few data


Second, the data structure

sorted set- ordered set in two implementations have in redis

1.ziplist, compression doubly linked list, related links

2.skiplist, jump table implementation


Three, skiplist data structure


score: score, used for sorting

backward: a data before the first layer, i.e., span = 1

Each node node layer represented by: level []

forward: the next node in the hierarchy

span: get to the next node in the hierarchy, the actual number of nodes across, is also convenient for use zrange ranking queries etc.


Four, Notes

4.1 Insert Data

1. When inserting the data by Level [] nodes need to compare quickly skip quickly locate the position of the node

The height of the level 2. When a new node is inserted, level [] hierarchy determined by the random

3. Every time span and then update the affected, span representing the number of nodes in the next layer node node should reach to cross


4.2 query list, such as zrange

1. The first start, by Level [] and every rank to quickly locate the starting position of the first layer

2 and then according to end, to output the result to the user


Fifth, parameter control

redis profile zset in the end is used to control the use ziplist (compression doubly linked lists) or skiplist (jump table) parameters:

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

zset-max-ziplist-entries zset ziplist storage when used, to limit the maximum number of entries stored

zset-max-ziplist-value zset ziplist storage when used, the maximum number of bytes stored in each node

Violate these two constraints, will result in the data structure ziplist zset switching data structure for skiplist

The reason for using zset ziplist, mainly due to fragmented data in less time, saving occupied content


Published 140 original articles · won praise 28 · views 180 000 +

Guess you like

Origin blog.csdn.net/qq_16097611/article/details/79939748