行业知识
5、Redis-Zset【常用】
2026-11-04 00:40:52
来源:互联网转载
一、简要说明
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) 2127.0.0.1:6379> zrange rank 0 -11) "Zy"2) "Trxcx"127.0.0.1:6379> zincrby rank 2000 Zy"4000"127.0.0.1:6379> zrange rank 0 -1 withscores1) "Trxcx"2) "3000"3) "Zy"4) "4000"127.0.0.1:6379> zrevrange rank 0 -11) "Zy"2) "Trxcx"127.0.0.1:6379> zrank rank Trxcx(integer) 0127.0.0.1:6379> zrevrank rank Trxcx(integer) 1127.0.0.1:6379> zcard rank(integer) 2
三、Redis中Zset类型应用场景
热搜排行榜
()上一篇:服务器怎么访问静态文件?
下一篇:服务器主板坏了怎么拿数据?