redis教程: zset命令

2019-08-06  本文已影响0人  warmsirius

zset类型

一、增加

1. 添加

zadd key score1 member1 score2 member2 ...
127.0.0.1:6379[1]> zadd a4 4 lisi 5 zhangsan 6 wangwu
(integer) 3
127.0.0.1:6379[1]> type a4
zset

二、获取

1. 返回指定范围内的元素

zrange key start stop
127.0.0.1:6379[1]> zrange a4 0 -1
1) "lisi"
2) "zhangsan"
3) "wangwu"

2. 返回score(权重)在min和max之间(闭区间)的成员

zrangebyscore key min max
127.0.0.1:6379[1]> zrangebyscore a4 5 6
1) "zhangsan"
2) "wangwu"

3. 返回成员的score值

zscore key member
127.0.0.1:6379[1]> zscore a4 zhangsan
"5"

三、删除

1. 删除指定元素

zrem key member1 member2 ...
127.0.0.1:6379[1]> zrem a4 zhangsan
(integer) 1
127.0.0.1:6379[1]> zrange a4 0 -1
1) "lisi"
2) "wangwu"

2. 删除权重在制定范围内的元素

zremrangebyscore key min max
127.0.0.1:6379[1]> zremrangebyscore a4 5 6
(integer) 1
127.0.0.1:6379[1]> zrange a4 0 -1
1) "lisi"
上一篇下一篇

猜你喜欢

热点阅读