ZSet集合
Zset 集合与set集合相似,Zset只是加了一个标识,让其变成一个有序的集合。
1.添加值与遍历值:zadd 与 zrange
127.0.0.1:6379> zadd myset 1 one 2 two 3 three
(integer) 3
127.0.0.1:6379> zrange myset 0 -1
1) "one"
2) "two"
3) "three"
2.升序 与降序 :zrangebyscore 与zrevrange
127.0.0.1:6379> ZRANGEBYSCORE myset -inf inf # inf表示正无穷大 -inf 表示负无穷大 。此处表示一个要排序的区间
1) "one"
2) "two"
3) "three"
127.0.0.1:6379> zrangebyscore myset -inf inf withscores # 表示带上 key
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
127.0.0.1:6379> zrevrange myset 0 -1 #降序查看
1) "three"
2) "two"
1) "one"
3.移除指定的元素,以及查看元素长度:zrem 与 zcard
127.0.0.1:6379> zrem myset one
(integer) 1
127.0.0.1:6379> zrange myset 0 -1
1) "two"
2) "three"
127.0.0.1:6379> zcard myset
(integer) 2
4.查看区间中的个数:zcount
127.0.0.1:6379> zcount myset 0 3
(integer) 3
127.0.0.1:6379> zrange myset 0 -1
1) "one"
2) "two"
3) "three"