Zset,即sorted set,有序集合。
Zset中的每个元素关联一个double类型的分数,之后可以根据这个分数为集合中的成员进行从小到大的排序。
key | value | ||
rank | member | score | |
Trxcx | 3000 | ||
Zy | 2000 | ||
Rt | 1000 |
格式 | 含义 | 例子 |
zadd key score member | 往key中添加member元素,并为score赋值 | zadd rank 3000 Trxcx 2000 Zy |
zincrby key increment member | 将key中的member元素,score增加increment | zincrby rank 2000 Zy |
zrange key start stop [withscores] | key中元素按照score升序排列,可选是否同时输出score | zrange rank 0 -1 |
zrevrange key start stop [withscores] | key中元素按照score降序排列,可选是否同时输出score | zrevrange rank 0 -1 |
zrank key member | 返回member在key中的正序排名(从低到高,从0开始) | zrank rank Trxcx |
zrevrank key member | 返回member在key中的倒序排名(从高到低,从0开始) | zrevrank rank Trxcx |
zcard key | 返回key中元素个数 | zcard rank |
- 127.0.0.1:6379> zadd rank 3000 Trxcx 2000 Zy
- (integer) 2
- 127.0.0.1:6379> zrange rank 0 -1
- 1) "Zy"
- 2) "Trxcx"
- 127.0.0.1:6379> zincrby rank 2000 Zy
- "4000"
- 127.0.0.1:6379> zrange rank 0 -1 withscores
- 1) "Trxcx"
- 2) "3000"
- 3) "Zy"
- 4) "4000"
- 127.0.0.1:6379> zrevrange rank 0 -1
- 1) "Zy"
- 2) "Trxcx"
- 127.0.0.1:6379> zrank rank Trxcx
- (integer) 0
- 127.0.0.1:6379> zrevrank rank Trxcx
- (integer) 1
- 127.0.0.1:6379> zcard rank
- (integer) 2
热搜排行榜