Zset Common operations

Source: Internet
Author: User

18, Zset common Operation
127.0.0.1:6379> zadd zset1 1 ABC #创建有序集合
(integer) 1
127.0.0.1:6379> zadd zset1 aabc #创建有序集合
(integer) 1
127.0.0.1:6379> zadd zset1 5 aaa #创建有序集合
(integer) 1
127.0.0.1:6379> zadd zset1 BBB #创建有序集合
(integer) 1
127.0.0.1:6379> zadd zset1 888 szk #创建有序集合
(integer) 1
127.0.0.1:6379> zrange zset1 0-1 #显示所有元素, displayed sequentially
1) "ABC"
2) "AAA"
3) "AABC"
4) "BBB"
5) "Szk"
127.0.0.1:6379> zrange zset1 0-1 withscores #可以带上分值
1) "ABC"
2) "1"
3) "AAA"
4) "5"
5) "AABC"
6) "Ten"
7) "BBB"
8) " the"
9) "Szk"
"888"

127.0.0.1:6379> zrem zset1 ABC #删除指定元素
(integer) 1
127.0.0.1:6379> zrange zset1 0-1 withscores
1) "AAA"
2) "5"
3) "AABC"
4) "Ten"
5) "BBB"
6) " the"
7) "Szk"
8) "888"

127.0.0.1:6379> zrank zset1 szk #返回元素的索引值, index value starting from 0, sorted by score forward

(integer) 0
127.0.0.1:6379> zrevrank zset1 szk #同上, the difference is, by score reverse order
(integer) 3

127.0.0.1:6379> zcard zset1 #查看集合元素的个数
(integer) 4
127.0.0.1:6379> zcount zset1 1 #查看分值区间内的元素个数
(integer) 2

127.0.0.1:6379> zrangebyscore zset1 1 withscores #返回分支范围在1-100 elements
1) "AAA"
2) "5"
3) "AABC"
4) "Ten"
5) "BBB"
6) " the"
127.0.0.1:6379> zrangebyscore zset1 0 #删除分支范围在0-10 elements, sorted by score
1) "AAA"

2) "AABC"


zremrangbyrank zset 0 2 //delete element of index range 0-2, sort by sroce


zremrangebyscore zset 1 //delete element of score range 1-10


Zset Common operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.