Redis命令-有序集合-zrank

 

原文

http://redis.io/commands/zrank

 

简介

Determine the index of a member in a sorted set.

 

确定有序集合中成员的索引。

 

语法

ZRANK key member

 

版本

Available since 2.0.0.

 

自2.0.0版本可用。

 

时间复杂度

Time complexity: O(log(N))

 

描述

Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high. The rank (or index) is 0-based, which means that the member with the lowest score has rank 0.

 

返回有序集合中成员的次序,按照分数从低到高排序。次序(或索引)是基于0的,这意味着分数最低的成员的次序为0。

 

Use ZREVRANK to get the rank of an element with the scores ordered from high to low.

 

使用ZREVRANGE获取元素的次序,按照分数由高到低排序。

 

返回值

If member exists in the sorted set, Integer reply: the rank of member.

If member does not exist in the sorted set or key does not exist, Bulk string reply: nil.

 

1)如果成员在有序集合中存在,返回成员的次序。
2)如果成员在有序集合中不存在,或者key不存在,返回nil。

 

例子

redis>  ZADD myzset 1 "one"
(integer) 1
redis>  ZADD myzset 2 "two"
(integer) 1
redis>  ZADD myzset 3 "three"
(integer) 1
redis>  ZRANK myzset "three"
(integer) 2
redis>  ZRANK myzset "four"
(nil)
redis>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值