存值:zaddmyset 1 one取值:zrangemyset 0 -1
127.0.0.1:6379> zadd myset 1 one #存值 分值為1
(integer) 1
127.0.0.1:6379> zadd myset 3 three #存值 分值為3
(integer) 1
127.0.0.1:6379> zadd myset 2 two #存值 分值為2
(integer) 1
127.0.0.1:6379> zrange myset 0 -1 #取值 預設按分值排序
1) "one"
2) "two"
3) "three"
排序(公升序):zrangebyscoremoney -inf +inf排序(降序):zrevrangemoney 0 -1 withscores
127.0.0.1:6379> zadd money 2500 zhangsan
(integer) 1
127.0.0.1:6379> zadd money 1800 lishi
(integer) 1
127.0.0.1:6379> zadd money 1600 wangwu
(integer) 1
127.0.0.1:6379> zadd money 3000 zhaoliu
(integer) 1
127.0.0.1:6379> zrangebyscore money -inf +inf #從負無窮大到正無窮大 公升序
1) "wangwu"
2) "lishi"
3) "zhangsan"
4) "zhaoliu"
127.0.0.1:6379> zrangebyscore money -inf +inf withscores #把分值和值一併查詢出來
1) "wangwu"
2) "1600"
3) "lishi"
4) "1800"
5) "zhangsan"
6) "2500"
7) "zhaoliu"
8) "3000"
127.0.0.1:6379> zrangebyscore money -inf 2000 withscores #只查詢2000以內的
1) "wangwu"
2) "1600"
3) "lishi"
4) "1800"
127.0.0.1:6379> zrevrange money 0 -1 withscores #降序查詢
1) "zhaoliu"
2) "3000"
3) "lishi"
4) "1800"
5) "wangwu"
6) "1600"
移除指定的元素:zremmoney zhangsan
127.0.0.1:6379> zrange money 0 -1
1) "wangwu"
2) "lishi"
3) "zhangsan"
4) "zhaoliu"
127.0.0.1:6379> zrem money zhangsan #移除zhangsan這個元素
(integer) 1
127.0.0.1:6379> zrange money 0 -1
1) "wangwu"
2) "lishi"
3) "zhaoliu"
移除指定的元素:zremmoney zhangsan
127.0.0.1:6379> zrange money 0 -1
1) "wangwu"
2) "lishi"
3) "zhangsan"
4) "zhaoliu"
127.0.0.1:6379> zrem money zhangsan #移除zhangsan這個元素
(integer) 1
127.0.0.1:6379> zrange money 0 -1
1) "wangwu"
2) "lishi"
3) "zhaoliu"
查詢有序集合中的元素個數:zcardmoney
127.0.0.1:6379> zrange money 0 -1
1) "wangwu"
2) "lishi"
3) "zhaoliu"
127.0.0.1:6379> zcard money
(integer) 3
統計區間值個數:zcountmoney 0 2000
127.0.0.1:6379> zrange money 0 -1 withscores
1) "zhangsan"
2) "1000"
3) "wangwu"
4) "1600"
5) "lishi"
6) "1800"
7) "zhaoliu"
8) "3000"
127.0.0.1:6379> zcount money 0 2000 #統計0-2000之間的個數
(integer) 3
有序集合 REDIS ZSET
命令 command key score value zadd myzset 1 one key是作為db最上層字典索引的key 儲存到底層的是score和value 1.如果第乙個元素符合以下條件的話,就建立乙個 redis encoding ziplist 編碼的有序集 redis zset底層...
Redis Zset有序集合
向有序集合新增乙個或多個成員,或者更新已存在成員的分數 zadd zset集合 score1 v1.scoren vn通過索引區間返回有序集合成指定區間內的成員 zrange zset集合 start stop withscores 通過分數返回有序集合指定區間內的成員 zrangebyscore ...
redis Zset有序集合
127.0.0.1 6379 zadd zset 1 one 新增乙個元素 integer 1 127.0.0.1 6379 zadd zset 2 two 3 three 新增多個元素 integer 2 127.0.0.1 6379 zrange zset 0 1 1 one 2 two 3 t...