TDIGEST.RANK

Syntax
TDIGEST.RANK key value [value ...]
Available in:
Redis Stack / Bloom 2.4.0
Time complexity:
O(N) where N is the number of values specified.

对于每个输入值(浮点数),返回该值的估计排名(草图中小于该值的观测值数量 + 等于该值的观测值数量的一半)。

可以在一次调用中检索多个排名。

必需的参数

key is key name for an existing t-digest sketch.
value is input value for which the rank should be estimated.

返回值

Array reply - 一个包含 rank_1, rank_2, ..., rank_V 的整数数组:

  • -1 - 当 value 小于最小观测值的值时。
  • 观测值的数量 - 当value大于最大观测值的值时。
  • 否则:估计(小于value的观测数 + 等于value的观测数的一半)。

0 是最小观测值的秩。

n-1 是最大观测值的排名;n 表示添加到草图中的观测数量。

如果草图为空,所有值均为-2。

示例

redis> TDIGEST.CREATE s COMPRESSION 1000
OK
redis> TDIGEST.ADD s 10 20 30 40 50 60
OK
redis> TDIGEST.RANK s 0 10 20 30 40 50 60 70
1) (integer) -1
2) (integer) 0
3) (integer) 1
4) (integer) 2
5) (integer) 3
6) (integer) 4
7) (integer) 5
8) (integer) 6
redis> TDIGEST.REVRANK s 0 10 20 30 40 50 60 70
1) (integer) 6
2) (integer) 5
3) (integer) 4
4) (integer) 3
5) (integer) 2
6) (integer) 1
7) (integer) 0
8) (integer) -1  
redis> TDIGEST.CREATE s COMPRESSION 1000
OK
redis> TDIGEST.ADD s 10 10 10 10 20 20
OK
redis> TDIGEST.RANK s 10 20
1) (integer) 2
2) (integer) 5
redis> TDIGEST.REVRANK s 10 20
1) (integer) 4
2) (integer) 1

RATE THIS PAGE
Back to top ↑