Redis命令zrange,zrangebyscore,zrevrank,zremrangebyscore

来源:互联网 发布:观军事知天下视频730天 编辑:程序博客网 时间:2024/06/13 23:12

zrange:索引的范围检索(withScores,递增)-->zrevrange(递减)

redis 127.0.0.1:6779> zadd ss 12 a(integer) 0redis 127.0.0.1:6779> zadd ss 5 b(integer) 1redis 127.0.0.1:6779> zadd ss 1000 c(integer)

zrange

redis 127.0.0.1:6779> zrange ss 0 -11) "b"2) "a"3) "c"

zrange withscores

redis 127.0.0.1:6779> zrange ss 0 -1 withscores1) "b"2) "5"3) "a"4) "12"5) "c"6) "1000"

注意这里检索的范围是索引的值

redis 127.0.0.1:6779> zrange ss 0 1  withscores1) "b"2) "5"3) "a"4) "12"

zrangebyscore :score的范围来检索(这个时候需要知道score的范围)

redis 127.0.0.1:6779> zrangebyscore ss 100 1500  withscores1) "c"2) "1000"redis 127.0.0.1:6779> zrangebyscore ss 12 1500  withscores1) "a"2) "12"3) "c"4) "1000"redis 127.0.0.1:6779> zrangebyscore ss 1 15  withscores1) "b"2) "5"3) "a"4) "12"

zrevrank,返回成员的排名

redis 127.0.0.1:6779> zrange ss 0 -1 withscores1) "b"2) "5"3) "a"4) "12"5) "c"6) "1000"redis 127.0.0.1:6779> zrevrank ss a(integer) 1

zremrangebyscore 删除指定score的元素,zremrangebyrank删除指定排名区间的元素

redis 127.0.0.1:6779> zrange ss 0 -1 withscores1) "b"2) "5"3) "a"4) "12"5) "c"6) "1000"redis 127.0.0.1:6779> aremr(error) ERR unknown command 'aremr'redis 127.0.0.1:6779> zremrangebyscore ss 1 12(integer) 2redis 127.0.0.1:6779> zrange ss 0 -1 withscores1) "c"2) "1000"redis 127.0.0.1:6779>
1 0
原创粉丝点击