SortedSet

SortedSet

127.0.0.1:6379> help zadd

  ZADD key [NX|XX] [GT|LT] [CH] [INCR] score member [score member ...]
  summary: Add one or more members to a sorted set, or update its score if it already exists
  since: 1.2.0
  group: sorted_set

127.0.0.1:6379> zadd fruits 3.2 香蕉
(integer) 1
127.0.0.1:6379> zadd fruits 2.0 西瓜
(integer) 1
127.0.0.1:6379> zadd fruits 4.0 石榴 7.0 梨子 6.8 芒果
(integer) 3
127.0.0.1:6379> zrank fruits 西瓜
(integer) 0
127.0.0.1:6379> zrank fruits 石榴
(integer) 2
127.0.0.1:6379> zrange fruits 1 3
1) "\xe9\xa6\x99\xe8\x95\x89"
2) "\xe7\x9f\xb3\xe6\xa6\xb4"
3) "\xe8\x8a\x92\xe6\x9e\x9c"
127.0.0.1:6379> zrange fruits 1 3 withscores
1) "\xe9\xa6\x99\xe8\x95\x89"
2) "3.2000000000000002"
3) "\xe7\x9f\xb3\xe6\xa6\xb4"
4) "4"
5) "\xe8\x8a\x92\xe6\x9e\x9c"
6) "6.7999999999999998"
127.0.0.1:6379> zrevrange fruits 1 3 withscores
1) "\xe8\x8a\x92\xe6\x9e\x9c"
2) "6.7999999999999998"
3) "\xe7\x9f\xb3\xe6\xa6\xb4"
4) "4"
5) "\xe9\xa6\x99\xe8\x95\x89"
6) "3.2000000000000002"
127.0.0.1:6379> zrem fruits 石榴
(integer) 1
127.0.0.1:6379> zrevrange fruits 0 -1
1) "\xe6\xa2\xa8\xe5\xad\x90"
2) "\xe8\x8a\x92\xe6\x9e\x9c"
3) "\xe9\xa6\x99\xe8\x95\x89"
4) "\xe8\xa5\xbf\xe7\x93\x9c"
127.0.0.1:6379> zadd fruits 3 西瓜
(integer) 0"
127.0.0.1:6379> zrevrange fruits 0 -1 withscores
1) "\xe6\xa2\xa8\xe5\xad\x90"
2) "7"
3) "\xe8\x8a\x92\xe6\x9e\x9c"
4) "6.7999999999999998"
5) "\xe9\xa6\x99\xe8\x95\x89"
6) "3.2000000000000002"
7) "\xe8\xa5\xbf\xe7\x93\x9c"
8) "3"
127.0.0.1:6379> zadd fruits 3.2 西瓜
(integer) 0
127.0.0.1:6379> zrevrange fruits 0 -1 withscores
1) "\xe6\xa2\xa8\xe5\xad\x90"
2) "7"
3) "\xe8\x8a\x92\xe6\x9e\x9c"
4) "6.7999999999999998"
5) "\xe9\xa6\x99\xe8\x95\x89"
6) "3.2000000000000002"
7) "\xe8\xa5\xbf\xe7\x93\x9c"
8) "3.2000000000000002"
127.0.0.1:6379> zscore fruits 西瓜
"3.2000000000000002"
127.0.0.1:6379> zincrby fruits -1.2 西瓜
"2"
127.0.0.1:6379> zincrby fruits 2.2 香蕉
"5.4000000000000004"
127.0.0.1:6379> zrangebyscore fruits 3 6
1) "\xe9\xa6\x99\xe8\x95\x89"
127.0.0.1:6379> zrangebyscore fruits 3 6 withscores
1) "\xe9\xa6\x99\xe8\x95\x89"
2) "5.4000000000000004"
127.0.0.1:6379> zrangebyscore fruits 3 10
1) "\xe9\xa6\x99\xe8\x95\x89"
2) "\xe8\x8a\x92\xe6\x9e\x9c"
3) "\xe6\xa2\xa8\xe5\xad\x90"
127.0.0.1:6379> zrangebyscore fruits 3 10 limit 1 2
1) "\xe8\x8a\x92\xe6\x9e\x9c"
2) "\xe6\xa2\xa8\xe5\xad\x90"
127.0.0.1:6379> zrange fruits 0 -1
1) "\xe8\xa5\xbf\xe7\x93\x9c"
2) "\xe9\xa6\x99\xe8\x95\x89"
3) "\xe8\x8a\x92\xe6\x9e\x9c"
4) "\xe6\xa2\xa8\xe5\xad\x90"
127.0.0.1:6379> zremrangebyrank fruits 1 2
(integer) 2
127.0.0.1:6379> zrange fruits 0 -1
1) "\xe8\xa5\xbf\xe7\x93\x9c"
2) "\xe6\xa2\xa8\xe5\xad\x90"
127.0.0.1:6379> zcard fruits
(integer) 2
127.0.0.1:6379> zcount fruits 2 3
(integer) 1
127.0.0.1:6379> zcount fruits 3 10
(integer) 1
127.0.0.1:6379> zcount fruits 10 100
(integer) 0
127.0.0.1:6379> zadd scores1 70 tom 80 peter 60 john
(integer) 3
127.0.0.1:6379> zrange scores1 0 -1
1) "john"
2) "tom"
3) "peter"
127.0.0.1:6379> zrange scores1 0 -1 withscores
1) "john"
2) "60"
3) "tom"
4) "70"
5) "peter"
6) "80"
127.0.0.1:6379> zadd score2 90 peter 60 ben
(integer) 2
127.0.0.1:6379> zrange score2 0 -1 withscores
1) "ben"
2) "60"
3) "peter"
4) "90"
127.0.0.1:6379> zunionstore scores-all 2 scores1 score2
(integer) 4
127.0.0.1:6379> zrange scores-all 0 -1 withscores
1) "ben"
2) "60"
3) "john"
4) "60"
5) "tom"
6) "70"
7) "peter"
8) "170"
127.0.0.1:6379> zunionstore scores-all1 2 scores1 score2 aggregate sum
(integer) 4
127.0.0.1:6379> zrange scores-all1 0 -1 withscores
1) "ben"
2) "60"
3) "john"
4) "60"
5) "tom"
6) "70"
7) "peter"
8) "170"
127.0.0.1:6379> zunionstore scores-all2 2 scores1 score2 aggregate max
(integer) 4
127.0.0.1:6379> zrange scores-all2 0 -1 withscores
1) "ben"
2) "60"
3) "john"
4) "60"
5) "tom"
6) "70"
7) "peter"
8) "90"
127.0.0.1:6379> zunionstore scores-all3 2 scores1 score2 aggregate min
(integer) 4
127.0.0.1:6379> zrange scores-all3 0 -1 withscores
1) "ben"
2) "60"
3) "john"
4) "60"
5) "tom"
6) "70"
7) "peter"
8) "80"
127.0.0.1:6379> zunionstore score-all1 2 scores1 score2 weights 2 0.5 aggregate sum
(integer) 4
127.0.0.1:6379> zrange score-all1 0 -1 withscores
1) "ben"
2) "30"
3) "john"
4) "120"
5) "tom"
6) "140"
7) "peter"
8) "205"
127.0.0.1:6379> zunionstore score-all1 2 scores1 score2 weights 2 0.5 aggregate max
(integer) 4
127.0.0.1:6379> zrange score-all1 0 -1 withscores
1) "ben"
2) "30"
3) "john"
4) "120"
5) "tom"
6) "140"
7) "peter"
8) "160"
127.0.0.1:6379> zunionstore score-all1 2 scores1 score2 weights 2 0.5 aggregate min
(integer) 4
127.0.0.1:6379> zrange score-all1 0 -1 withscores
1) "ben"
2) "30"
3) "peter"
4) "45"
5) "john"
6) "120"
7) "tom"
8) "140"
127.0.0.1:6379> zunionstore score-all1 2 scores1 score2 weights 2 2 aggregate sum
(integer) 4
127.0.0.1:6379> zrange score-all1 0 -1 withscores
1) "ben"
2) "120"
3) "john"
4) "120"
5) "tom"
6) "140"
7) "peter"
8) "340"
127.0.0.1:6379> zinterstore score-all3 2 scores1 score2 
(integer) 1
127.0.0.1:6379> zrange score-all3 0 -1 withscores
1) "peter"
2) "170"
127.0.0.1:6379> zinterstore score-all3 2 scores1 score2 aggregate sum
(integer) 1
127.0.0.1:6379> zrange score-all3 0 -1 withscores
1) "peter"
2) "170"
127.0.0.1:6379> zinterstore score-all3 2 scores1 score2 aggregate min
(integer) 1
127.0.0.1:6379> zrange score-all3 0 -1 withscores
1) "peter"
2) "80"
127.0.0.1:6379> zinterstore score-all3 2 scores1 score2 aggregate max
(integer) 1
127.0.0.1:6379> zrange score-all3 0 -1 withscores
1) "peter"
2) "90"
127.0.0.1:6379> zinterstore score-all3 2 scores1 score2  weights 2 0.5  aggregate sum
(integer) 1
127.0.0.1:6379> zrange score-all3 0 -1 withscores
1) "peter"
2) "205"
127.0.0.1:6379> zinterstore score-all3 2 scores1 score2  weights 2 0.5  aggregate max
(integer) 1
127.0.0.1:6379> zrange score-all3 0 -1 withscores
1) "peter"
2) "160"
127.0.0.1:6379> zinterstore score-all3 2 scores1 score2  weights 2 0.5  aggregate min
(integer) 1
127.0.0.1:6379> zrange score-all3 0 -1 withscores
1) "peter"
2) "45"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值