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

Ordered set

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

Share

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

Order set ordered set

Zadd key score1 value1 score2 value2..

Add element

Redis 127.0.0.1 hmm 6379 > zadd stu 18 lily 19 hmm 20 lilei 21 lilei

(integer) 3 (in this way, it is also unique)

(the sort is based on score...)

Zrem key value1 value2..

Purpose: delete elements in the collection

Zremrangebyscore key min max

Function: delete elements according to socre, delete score between [min,max]

Redis 127.0.0.1 6379 > zremrangebyscore stu 4 10

(integer) 2

Redis 127.0.0.1 6379 > zrange stu 0-1

1) "f"

Zremrangebyrank key start end

Function: delete elements by ranking, delete those ranked between [start,end]

Redis 127.0.0.1 redis > zremrangebyrank stu 0 1

(integer) 2

Redis 127.0.0.1 6379 > zrange stu 0-1

1) "c"

2) "e"

3) "f"

4) "g"

Zrank key member

Query the ranking of member (starting with the continuation of 0 places)

Zrevrank key memeber

Query the ranking of member (starting with 0 place reduction)

ZRANGE key start stop [WITHSCORES]

After sorting the collection, return the element of rank [start,stop] (starting at 0)

The default is ascending arrangement.

Withscores prints out the score, too.

Zrevrange key start stop

Function: sort the collections in descending order and choose the elements between the names [start,stop]

Zrangebyscore key min max [withscores] limit offset N

Function: after sorting the collection (rising and continuing), take the elements of score in [min,max]

And skip offset, take out N

Redis 127.0.0.1 6379 > zadd stu 1 a 3 b 4 c 9 e 12 f 15 g

(integer) 6

Redis 127.0.0.1 limit 6379 > zrangebyscore stu 3 12 limit 12 withscores

1) "c"

2) "4"

3) "e"

4) "9"

Zcard key

Returns the number of elements

Zcount key min max

Returns the number of elements in the [min,max] range

Zinterstore destination numkeys key1 [key2...]

[WEIGHTS weight [weight...]]

[AGGREGATE SUM | MIN | MAX]

To find the intersection of key1,key2, the weight of key1,key2 is weight1,weight2.

Aggregation method uses: sum | min | max

The result of the aggregation, saved in the dest collection

Note: how do you understand weights and aggregate?

A: what if there is an intersection and there is a socre,score for the intersection elements?

Aggregate sum- > score addition, min to find the minimum score, max maximum score

In addition: you can set the weight of different key through weigth. When intersecting, socre * weights

See the following example for details

Redis 127.0.0.1 6379 > zadd z1 2 a 3 b 4 c

(integer) 3

Redis 127.0.0.1 6379 > zadd z2 2.5 a 1 b 8 d

(integer) 3

Redis 127.0.0.1 6379 > zinterstore tmp 2 z1 z2

(integer) 2

Redis 127.0.0.1 6379 > zrange tmp 0-1

1) "b"

2) "a"

Redis 127.0.0.1 withscores 6379 > zrange tmp 0-1 withscores

1) "b"

2) "4"

3) "a"

4) "4.5"

Redis 127.0.0.1 aggregate sum 6379 > zinterstore tmp 2 z1 z2

(integer) 2

Redis 127.0.0.1 withscores 6379 > zrange tmp 0-1 withscores

1) "b"

2) "4"

3) "a"

4) "4.5"

Redis 127.0.0.1 aggregate min 6379 > zinterstore tmp 2 z1 z2

(integer) 2

Redis 127.0.0.1 withscores 6379 > zrange tmp 0-1 withscores

1) "b"

2) "1"

3) "a"

4) "2"

Redis 127.0.0.1 weights 6379 > zinterstore tmp 2 z1 z2 weights 12

(integer) 2

Redis 127.0.0.1 withscores 6379 > zrange tmp 0-1 withscores

1) "b"

2) "5"

3) "a"

4) "7"

(based on the data of the person who sold the least)

(based on the data of the person who sold the most)

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