Redis命令-有序集合-zremrangebyrank

本文介绍了 Redis 中用于从有序集合中删除指定索引范围内所有成员的命令 ZREMRANGEBYRANK 的使用方法。详细解释了该命令的工作原理、语法格式、版本兼容性和时间复杂度,并通过具体示例展示了如何操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

原文

http://redis.io/commands/zremrangebyrank

 

简介

Remove all members in a sorted set within the given indexes.

 

从有序集合中删除指定索引范围内的所有成员。

 

语法

ZREMRANGEBYRANK key start stop

 

版本

Available since 2.0.0.

 

自2.0.0版本可用。

 

时间复杂度

Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.

 

O(M*log(N)):N是有序集合中元素的数量,M是要删除的元素的数量。

 

描述

Removes all elements in the sorted set stored at key with rank between start and stop. Both start and stop are 0 -based indexes with 0 being the element with the lowest score. These indexes can be negative numbers, where they indicate offsets starting at the element with the highest score. For example: -1 is the element with the highest score, -2 the element with the second highest score and so forth.

 

从有序集合中删除索引在start和stop之间的所有元素。start和stop都是基于0的索引,0表示分数最低的元素。这些索引可以是负数,表示从分数最高的元素计算偏移。例如:-1表示分数最高的元素,-2表示分数次高的元素等等。

 

返回值

Integer reply: the number of elements removed.

 

删除的元素数量。

 

例子

redis>  ZADD myzset 1 "one"
(integer) 1
redis>  ZADD myzset 2 "two"
(integer) 1
redis>  ZADD myzset 3 "three"
(integer) 1
redis>  ZREMRANGEBYRANK myzset 0 1
(integer) 2
redis>  ZRANGE myzset 0 -1 WITHSCORES
1) "three"
2) "3"
redis>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值