命令 | 解释 |
---|---|
zadd | ~ key [NX|XX] [CH] [INCR] score member [score member ...] [score]:分值,其大小用以排序,可以重复。 [NX] : if not exist ; [XX] : if exist |
zrem | ~ key member [member ...] |
zscore | ~ key member (获取元素的score) |
zrange | ~ key start stop [WITHSCORES] (按下标获取元素内容) ~ key 0 -1 获取所有的元素 ~ key 0 -1 withsocres 获取所有的元素和分值 |
zrangebylex | ~ key min max [LIMIT offset count] 通过字典区间返回有序集合的成员 |
zrevrange | ~ key start stop [WITHSCORES] 逆向排序zrange |
zincrby | ~ key increment member(增加或减少元素的分数) |
zcard | ~ key | 返回元素的总个数 |
zrank | ~ key element(获取元素的下标) |
zrevrank | ~ key member 逆向排序zrank |
zcount | ~ key minScore maxScore(获取分值闭区间中元素的个数) |
zlexcount | ~ key min max 计算指定字典区间内成员数量 |
zremrangebyrank | ~ key start stop 删除指定排名内的升序元素 |
zremrangebyscore | ~ key start stop 删除指定分值内的升序元素 |
zremrangebylex | ~ key min max 移除给定的字典区间的所有成员 |
zrangebyscore | ~ key min max [WITHSCORES] [LIMIT offset count] |
zrevrangebyscore | ~ key max min [WITHSCORES] [LIMIT offset count] |
zinterstore 并集 | ~ destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX] |
zunionstore 交集 | ~ destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX] |
zscan | ~ key cursor [MATCH pattern] [COUNT count] 迭代有序集合中的元素(包括元素成员和元素分值) |
127.0.0.1:6379> zadd zset01 1 hello 2 world 5 worldhello 4 helloworld
(integer) 4
127.0.0.1:6379> zrange zset01 1 10
1) "world"
2) "helloworld"
3) "worldhello"
127.0.0.1:6379> zrange zset01 0 5
1) "hello"
2) "world"
3) "helloworld"
4) "worldhello"
127.0.0.1:6379> zrange zset01 0 4
1) "hello"
2) "world"
3) "helloworld"
4) "worldhello"
127.0.0.1:6379> zrange zset01 0 3
1) "hello"
2) "world"
3) "helloworld"
4) "worldhello"
127.0.0.1:6379> zscore zset0 helloworld
(nil)
127.0.0.1:6379> zscore zset01 helloworld
"4"
127.0.0.1:6379> zrem zset01 world hello
(integer) 2
127.0.0.1:6379> zrange zset01 0 5
1) "helloworld"
2) "worldhello"
127.0.0.1:6379> zscore zset01 helloworld
"4"
127.0.0.1:6379> zscore zset01 worldhello
"5"
127.0.0.1:6379> zincrby zset01 10 helloworld
"14"
127.0.0.1:6379> zscore zset01 helloworld
"14"
127.0.0.1:6379> zrange zset01 0 3
1) "worldhello"
2) "helloworld"
127.0.0.1:6379> zcard zset01
(integer) 2
127.0.0.1:6379> zrank zset01 helloworld
(integer) 1
127.0.0.1:6379> zrank zset01 worldhello
(integer) 0
127.0.0.1:6379> zrange zset01 0 -1
1) "worldhello"
2) "helloworld"
127.0.0.1:6379> zadd zset01 nx 10 apple 29 banana 7 orange
(integer) 3
127.0.0.1:6379> zrange zset01 0 -1 withscores
1) "worldhello"
2) "5"
3) "orange"
4) "7"
5) "apple"
6) "10"
7) "helloworld"
8) "14"
9) "banana"
10) "29"
127.0.0.1:6379> zcount zset01 10 20
(integer) 2
127.0.0.1:6379> zcount zset01 10 14
(integer) 2
127.0.0.1:6379> zcount zset01 10 13
(integer) 1
127.0.0.1:6379> zrangebyscore zset01 0 30 withscores limit 0 2
1) "worldhello"
2) "5"
3) "orange"
4) "7"
127.0.0.1:6379> zrangebyscore zset01 0 30 withscores
1) "worldhello"
2) "5"
3) "orange"
4) "7"
5) "apple"
6) "10"
7) "helloworld"
8) "14"
9) "banana"
10) "29"
127.0.0.1:6379> zrangebyscore zset01 0 30
1) "worldhello"
2) "orange"
3) "apple"
4) "helloworld"
5) "banana"
127.0.0.1:6379> zremrangebyrank zset01 0 1
(integer) 2
127.0.0.1:6379> zrange zset01 0 -1
1) "apple"
2) "helloworld"
3) "banana"
127.0.0.1:6379> zremrangebyscore zset01 10 14
(integer) 2
127.0.0.1:6379> zrange zset01 0 -1
1) "banana"
zset实战示例
网友评论