Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Common commands for Redis Collection set

Shulou Source: shulou.com Published: 2022-06-02 05:11:43 10月04日 Update

This article mainly explains the "Redis collection set common commands", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Redis collection set common commands" bar!

Set

> sadd name hello (integer) 1 > sadd name hello # repeat, cannot insert (integer) 0 > sadd name i am ok (integer) 3 > smembers name "hello"I"am"ok" > sismember name hello # check whether the value exists (integer) 1 > scard name # get length (integer) 4 > spop name # get the first "hello" ZSet

Zset is an ordered collection, it has the characteristics of SortedSet and HashMap in java, it is a collection that ensures that the internal value is unique, and there is a sort field score to sort, and its internal structure implements a jump list, commonly known as a jump table. Next, we will find a time to explain the implementation of the jump table in zset. Generally speaking, ranking is the most frequently used zset, such as the ranking of gifts in live streaming, the ranking of the number of fans, and so on.

Let's use some common commands.

> zadd name 2 world (integer) 1 > zadd name 1 hello (integer) 1 > zrange name 0-1 # sort "hello"world" > zrevrange name 0-1 # in ascending score order "world"hello" > zcard name # get the number of collections (integer) 2 > zscore name hello # get Internal score1.0 > zrem name world # Delete (integer) 1

Generally speaking, when we search an ordered list, we can use to traverse the entire list, but in order to consider the performance, we use dichotomy is the fastest, but the list needs to be randomly inserted and deleted, so the data is not suitable to do so. So we try to use linked lists, linked lists support random insertion and deletion very well, but linked lists can not be quickly found by dichotomy. So we use a method called jump list in redis to implement zset.

Thank you for your reading, the above is the content of "Redis collection set common commands", after the study of this article, I believe you have a deeper understanding of the problem of Redis collection set common commands, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Commands common use learning ordering generally speaking number dichotomy content sorting fastest next ascending order fields that is ideas performance situations data articles methods. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Tech Info Microsoft Docker Redmi