zset : 有分数有序的set
1 设置和获取
127.0.0.1:6379> zadd zset1 10 a
(integer) 1
127.0.0.1:6379> zadd zset1 50 b
(integer) 1
127.0.0.1:6379> zadd zset1 30 c
(integer) 1
127.0.0.1:6379> zrange zset1 0 -1
1) "a"
2) "c"
3) "b"
127.0.0.1:6379> zrevrange zset1 0 -1
1) "b"
2) "c"
3) "a"
127.0.0.1:6379> zrangebyscore zset1 0 40
1) "a"
2) "c"
2 大小
127.0.0.1:6379> zcard zset1
(integer) 3
3 计算分数范围内的元素
127.0.0.1:6379> zcount zset1 0 30
(integer) 2
4 获取索引及分数
127.0.0.1:6379> zrank zset1 b
(integer) 2
127.0.0.1:6379> zscore zset1 a
"10"
5 删除元素
127.0.0.1:6379> zrem zset1 a
(integer) 1
127.0.0.1:6379> zrange zset1 0 -1
1) "c"
2) "b"