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

Common operations of zset

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

XVIII. Common operation of zset

127.0.0.1 abc 6379 > zadd zset1 1 create an ordered set

(integer) 1

127.0.0.1 zadd zset1 6379 > 10 aabc # create an ordered set

(integer) 1

127.0.0.1 aaa 6379 > zadd zset1 5 create an ordered set

(integer) 1

127.0.0.1 bbb 6379 > zadd zset1 88 create ordered collections

(integer) 1

127.0.0.1 zadd zset1 6379 > 888 szk # create an ordered set

(integer) 1

127.0.0.1 6379 > ZRANGE zset1 0-1 # displays all elements in order

1) "abc"

2) "aaa"

3) "aabc"

4) "bbb"

5) "szk"

127.0.0.1 ZRANGE zset1 6379 > 0-1 withscores # can take a score

1) "abc"

2) "1"

3) "aaa"

4) "5"

5) "aabc"

6) "10"

7) "bbb"

8) "88"

9) "szk"

10) "888"

127.0.0.1 6379 > ZREM zset1 abc # Delete the specified element

(integer) 1

127.0.0.1 6379 > ZRANGE zset1 0-1 withscores

1) "aaa"

2) "5"

3) "aabc"

4) "10"

5) "bbb"

6) "88"

7) "szk"

8) "888"

127.0.0.1 6379 > zrank zset1 szk # returns the index value of the element, which is sorted by score positive direction starting from 0

(integer) 0

127.0.0.1 6379 > zrevrank zset1 szk # ditto, except that it is sorted in reverse order by score

(integer) 3

127.0.0.1 6379 > ZCARD zset1 # View the number of collection elements

(integer) 4

127.0.0.1 zcount zset1 6379 > 1 20 # View the number of elements in the score range

(integer) 2

127.0.0.1 withscores 6379 > zrangebyscore zset1 1 100 withscores # returns elements with branches in the range of 1-100

1) "aaa"

2) "5"

3) "aabc"

4) "10"

5) "bbb"

6) "88"

127.0.0.1 6379 > zrangebyscore zset1 0 10 # delete elements with branches in the range of 0-10, and sort by score

1) "aaa"

2) "aabc"

Zremrangbyrank zset 0 2 / / deletes the elements in the index range 0-2, sorting by sroce forward

Zremrangebyscore zset 1 10 / / Delete elements with scores ranging from 1 to 10

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