快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

Redis之zset类型及操作-创新互联

zset

成都创新互联专业为企业提供黄龙网站建设、黄龙做网站、黄龙网站设计、黄龙网站制作等企业网站建设、网页设计与制作、黄龙企业网站模板建站服务,十载黄龙做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。是string类型的有序集合
zadd:向名称为key的zset中添加元素member,score用于排序。如果该元素存在,则更新其顺序。
127.0.0.1:6379> zadd myzset 1 one
(integer) 1
127.0.0.1:6379> zadd myzset 2 two
(integer) 1
127.0.0.1:6379> zadd myzset 3 two
(integer) 0
127.0.0.1:6379> zrange myzset 0 -1 withscores
1) "one"
2) "1"
3) "two"
4) "3"
zrem:删除名称为key的zset中的元素member。
127.0.0.1:6379> zrange myzset 0 -1 withscores
1) "one"
2) "1"
3) "two"
4) "3"
127.0.0.1:6379> zrem myzset two
(integer) 1
127.0.0.1:6379> zrange myzset 0 -1 withscores
1) "one"
2) "1"
zincrby:如果在名称为key的zset中已经存在元素member,则该元素的score增加increment,否则向该集合中添加该元素,其score的值为increment。
127.0.0.1:6379> zadd myzset2 1 one
(integer) 1
127.0.0.1:6379> zadd myzset2 2 two
(integer) 1
127.0.0.1:6379> zrange myzset2 0 -1 withscores
1) "one"
2) "1"
3) "two"
4) "2"
127.0.0.1:6379> zincrby myzset2 2 one
"3"
127.0.0.1:6379> zrange myzset2 0 -1 withscores
1) "two"
2) "2"
3) "one"
4) "3"
zrank:返回名称为key的zset中member元素的排名(按score从小到大排序)即下标。
127.0.0.1:6379> zadd myzset3 1 one
(integer) 1
127.0.0.1:6379> zadd myzset3 2 two
(integer) 1
127.0.0.1:6379> zadd myzset3 3 three
(integer) 1
127.0.0.1:6379> zadd myzset3 5 five
(integer) 1
127.0.0.1:6379> zrange myzset3 0 -1 withscores
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
7) "five"
8) "5"
127.0.0.1:6379> zrank myzset3 two
(integer) 1
127.0.0.1:6379> zrank myzset3 three
(integer) 2
zrevrank:返回名称为key的zset中member元素的排名(按score从大到小排序)即下标
127.0.0.1:6379> zrange myzset3 0 -1 withscores
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
7) "five"
8) "5"
127.0.0.1:6379> zrevrank myzset3 five
(integer) 0
zrevrange:
127.0.0.1:6379> zrange myzset3 0 -1 withscores
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
7) "five"
8) "5"
127.0.0.1:6379> zrevrange myzset3 0 -1 withscores
1) "five"
2) "5"
3) "three"
4) "3"
5) "two"
6) "2"
7) "one"
8) "1"
zrangebyscore:
127.0.0.1:6379> zrangebyscore myzset3 2 3 withscores
1) "two"
2) "2"
3) "three"
4) "3"
zcount:
127.0.0.1:6379> zrange myzset3 0 -1 withscores
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
7) "five"
8) "5"
127.0.0.1:6379> zcount myzset3 2 3
(integer) 2
zcard:
127.0.0.1:6379> zrange myzset3 0 -1 withscores
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
7) "five"
8) "5"
127.0.0.1:6379> zcard myzset3
(integer) 4
zremrangebyrank:删除集合中排名在给定区间的元素。
127.0.0.1:6379> zrange myzset3 0 -1 withscores
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
7) "five"
8) "5"
127.0.0.1:6379> zremrangebyrank myzset3 1 1
(integer) 1
127.0.0.1:6379> zrange myzset3 0 -1 withscores
1) "one"
2) "1"
3) "three"
4) "3"
5) "five"
6) "5"
zremrangbyscore:
127.0.0.1:6379> zrange myzset3 0 -1 withscores
1) "one"
2) "1"
3) "three"
4) "3"
5) "five"
6) "5"
127.0.0.1:6379> zremrangebyscore myzset3 4 5
(integer) 1
127.0.0.1:6379> zrange myzset3 0 -1 withscores
1) "one"
2) "1"
3) "three"
4) "3"
网站题目:Redis之zset类型及操作-创新互联
文章网址:http://6mz.cn/article/dshoho.html

其他资讯