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

How to use Redis ordered set Zset

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

The purpose of this article is to share with you about how to use Redis ordered collection Zset. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Redis ordered set Zset (sorted set)

The difference from set: add a score value to set. Before set was K1 v1 v2 v3, now zset is K1 score v1 score v2

1.zadd/zrange

Zadd add element

Zrange View key element

Withscores View element score

127.0.0.1 ZADD zset01 9736 > integer 60 v1 70 v2 80 v3 90 v4 100 v5 (integer) 5127.0.0.1 ZRANGE zset01 0-11) "v1" 2) "v2" 3) "v3" 4) "v4" 5) "v5" 127.0.0.1 ZRANGE zset01 0-1 withscores 1) "v1" 2) "60" 3) "v2" 4) "70" 5) "v3" 6) "80" 7) "v4" 8) "90" 9) "v5" 10) "100" 2.zrangebyscore key start score end score

Find by score

(not included

Limit restricts reading of results, reading m items from n, similar to paging

127.0.0.1 ZRANGEBYSCORE zset01 9736 > ZRANGEBYSCORE zset01 60901) "v1" 2) "v2" 3) "v3" 4) "v4" / greater than or equal to 60 less than 90127.0.1 limit 9736 > ZRANGEBYSCORE zset01 60 (901) "v1" 2) "v2" 3) "v3" / / intercepted from the second article 2 127.0.1 limit 9736 > ZRANGEBYSCORE zset01 60 90 limit 2 21) "v3" 2) "v4" 3.zram deletes key Data specified: 127.0.0.1 zrem zset01 v5 (integer) 1127.0.0.1 ZRANGE zset01 9736 > ZRANGE zset01 0-11) "v1" 2) "v2" 3) "v3" 4) "v4" 127.0.1 ZRANGE zset01 0-1 withscores1) "v1" 2) "60" 3) "v2" 4) "70" 5) "v3" 6) "80" 7) "v4" 8) "90" 4. Zcard/zcount key score interval / zrank key values value The function is to get the subscript value / zscore key corresponding value and get the score

Zcard: count the number of values in key

Zcount: count the number of median values in the score stage

Zrank statistics ranking where the median key lies

Zscore calculates the score of the mean value of key

127.0.0.1 zcard zset01 (integer) 4127.0.0.1 zcard zset01 9736 > integer 6080 (integer) 3127.0.0.1 ZRANK zset01 v4 (integer) 3127.0.1 zcount zset01 9736 > integer v4 "90" 5.zrevrank key values value The function is to reverse the subscript value 127.0.0.1 zrevrank zset01 9736 > zrevrank zset01 v4 (integer) 0127.0.0.1 zrevrange zset01 0-11) "v4" 2) "v3" 3) "v2" 4) "v1" 6.zrevrangebyscore from the end score to the start score, reverse 127.0.0.1 zrevrange zset01 9736 > zrevrangebyscore zset01 90601) "v4" 2) "v3" 3) "v2" 4) "v1" thank you for reading! This is the end of this article on "how to use Redis ordered set Zset". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

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

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report