LT 如果新的分数比原来的小则更新,不新增 //ver>=6.2: Added the GT and LT options.
GT 如果新的分数比原来的大则更新,不新增 //ver>=6.2: Added the GT and LT options.
CH 修改返回值为发生变化的成员个数(区别原来是返回新增的成员个数)
INCR 类似ZINCRBY命令,增加成员的分数,只能增加一个成员
return value
默认返回新增的成员数量,不包括更新的 If the INCR option is specified, the return value will be Bulk string reply:
The new score of member (a double precision floating point number) represented as string, or nil if the operation was aborted (when called with either the XX or the NX option).
127.0.0.1:6379> ZADD set0 10 a 20 b (integer) 2 127.0.0.1:6379> ZADD set0 XX 11 a 30 c //更新a,新增c失败 (integer) 0 127.0.0.1:6379> ZRANGE set0 0 -1 WITHSCORES 1) "a" 2) "11" 3) "b" 4) "20" 127.0.0.1:6379> ZADD set0 NX 40 d 12 a //新增d,更新a失败 (integer) 1 127.0.0.1:6379> ZRANGE set0 0 -1 WITHSCORES 1) "a" 2) "11" 3) "b" 4) "20" 5) "d" 6) "40" 127.0.0.1:6379> ZADD set0 LT 10 a 21 b (error) ERR syntax error 127.0.0.1:6379> ZADD set0 LT 10 a //当前版本不支持 (error) ERR syntax error 127.0.0.1:6379> ZADD set0 CH 12 a 30 c //变化变化的总数 (integer) 2 127.0.0.1:6379> ZRANGE set0 0 -1 WITHSCORES 1) "a" 2) "12" 3) "b" 4) "20" 5) "c" 6) "30" 7) "d" 8) "40" 127.0.0.1:6379> ZADD set0 CH XX 11 a //配合其他参数 (integer) 1 127.0.0.1:6379> ZADD set0 XX 13 a //区别老的返回值 (integer) 0 127.0.0.1:6379> ZADD set0 50.1 e //支持浮点数 (integer) 1 127.0.0.1:6379> ZRANGE set0 0 -1 WITHSCORES 1) "a" 2) "13" 3) "b" 4) "20" 5) "c" 6) "30" 7) "d" 8) "40" 9) "e" 10) "50.100000000000001"
ZCARD
返回key的元素个数,如果key不存在,返回0
1 2 3 4 5 6
127.0.0.1:6379> zadd set1 1 a 2 b 3 c (integer) 3 127.0.0.1:6379> zcard set1 (integer) 3 127.0.0.1:6379> zcard set10 (integer) 0
ZCOUNT
ZCOUNT key min max
1 2 3 4 5 6 7 8 9 10
127.0.0.1:6379> zadd set7 1 a 3 b 3 c 4 d (integer) 4 127.0.0.1:6379> zcount set7 1 4 (integer) 4 127.0.0.1:6379> zcount set7 [1 (4 //不支持[ (error) ERR min or max is not a float 127.0.0.1:6379> zcount set7 1 (4 (integer) 3 127.0.0.1:6379> zcount set7 -inf +inf (integer) 4
ZINCRBY
ZINCRBY key increment member
给元素的分数增加/递减
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
127.0.0.1:6379> zrange set7 0 -1 withscores 1) "a" 2) "1" 3) "b" 4) "3" 5) "c" 6) "3" 7) "d" 8) "4" 127.0.0.1:6379> zincrby set7 2 a "3" 127.0.0.1:6379> zincrby set7 -1 a "2" 127.0.0.1:6379> zincrby set7 5 e "5"
127.0.0.1:6379> zadd set4 1 a 2 b 3 c 4 d 5 e 6 f (integer) 6 127.0.0.1:6379> zrangebyscore set4 - + //不支持这种格式 (error) ERR min or max is not a float 127.0.0.1:6379> zrangebyscore set4 -inf +inf //所有元素 1) "a" 2) "b" 3) "c" 4) "d" 5) "e" 6) "f" 127.0.0.1:6379> zrangebyscore set4 -inf +inf LIMIT 1 2 //limit 1) "b" 2) "c" 127.0.0.1:6379> zrangebyscore set4 -inf +inf WITHSCORES LIMIT 1 2 //withscores 1) "b" 2) "2" 3) "c" 4) "3" 127.0.0.1:6379> zrangebyscore set4 [1 [3 WITHSCORES LIMIT 1 2 //不支持[ (error) ERR min or max is not a float 127.0.0.1:6379> zrangebyscore set4 1 3 WITHSCORES LIMIT 1 2 1) "b" 2) "2" 3) "c" 4) "3" 127.0.0.1:6379> zrangebyscore set4 (1 (3 WITHSCORES LIMIT 1 2 (empty list or set) 127.0.0.1:6379> zrangebyscore set4 (1 (3 WITHSCORES //支持( 1) "b" 2) "2"
ZRANK
ZRANK key member
返回元素按score的排名,从低到高,不存在的话返回nil
1 2 3 4 5 6 7 8
127.0.0.1:6379> zadd set5 1 a 2 b 3 c 4 d 5 e (integer) 5 127.0.0.1:6379> zrank set5 a (integer) 0 127.0.0.1:6379> zrank set5 b (integer) 1 127.0.0.1:6379> zrank set5 k (nil)