Title: Redis Sorted sets
date: 2015-05-05 13:08:36 +0800
comments: true
category: Redis
tags: redis,linux
Redis Sorted-Set
zadd
ZADD key score member [score member ...]
e.g.
zadd myzset 1 one
# zrange myzset 0 -1 withscores
zrem
ZREM key member [member ...]
e.g.
zrem myzset one
zrange
ZRANGE key start stop [WITHSCORES]
e.g.
zrange myzset 0 -1 withscores
zrevrange
ZREVRANGE key start stop [WITHSCORES]
返回名称为key的zset(按score从大到小排序)中的index从start到end的所有元素
zincrby
ZINCRBY key increment member
如果在名称为key的zset中已经存在元素member,则该元素的score增加increment;否则向集合中添加该元素,其score的值为increment
e.g.
zincrby key 3 one
zincrby key 1 five
127.0.0.1:6379[8]> ZRANGE myzset 0 -1 withscores
1) "five"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
7) "one"
8) "4"
9) "four"
10) "7"
zrank
ZRANK key member
返回名称为key的zset中member元素的排名(按score从小到大排序)即下标
e.g.
127.0.0.1:6379[8]> ZRANGE myzset 0 -1 withscores
1) "five"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
7) "one"
8) "4"
9) "four"
10) "7"
127.0.0.1:6379[8]> zrank myzset five
(integer) 0
127.0.0.1:6379[8]> zrank myzset one
(integer) 3
zrevrank
ZREVRANK key member
返回名称为key的zset中member元素的排名(按score从大到小排序)即下标
zrangebyscore
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
e.g.
zrangebysocre myzset 2 4 withscores
zcount
ZCOUNT key min max
返回集合中score在给定区间的数量
e.g.
zcount key
zcard
集合个数
ZCARD key
zscore
返回给定元素对应的score
ZSCORE key member