Get Values By Rank Range¶
Description¶
This operation returns values for a range of rank numbers. A rank in a sorted set determines the position of an element. For more information about the rank, refer to the Hive Overview section of this guide.
Method¶
Backendless.Hive( hiveName ).SortedSetStore( keyName ).getRangeByRank(
startRank,
stopRank,
{
withScores: boolean,
reverse: boolean
}): Promise;
where:
Argument | Description |
---|---|
hiveName |
Name of a hive where the operation is performed. String value. |
keyName |
Key name identifying a sorted-set. String value. |
startRank/stopRank |
the inclusive range of ranks (positions) of elements, between which the items are requested (the maximum for returning elements is the difference between these two parameters which cannot be bigger than 10000); The stopRank parameter can also be a negative number indicating offset from the end of the sorted set, with -1 being the last element of the sorted set, -2 the penultimate element, and so on. |
withScores |
Optional parameter, defaults to false. When this parameter is set to true , then the item score is returned. |
reverse |
Optional parameter, defaults to false . When set to false , items in the requested sorted set are sorted in ascending order of their scores. When set to true , items are sorted in descending order of their scores. |
Return Value¶
When the withScores
parameter is set to true
, the return value is an array of score-value pairs. Each pair is also an array of two elements - the score and the value.
Example¶
The example below returns an array of score-value pairs where the values are within a range identified by the startRank
and the stopRank
parameters. Since the [scores]
parameter is set to true
, the response includes both values and the corresponding scores.
await Backendless.Hive('leaderboard').SortedSetStore('players').getRangeByRank(1, 3, { withScores: true, reverse: true })
where:
Argument | Description |
---|---|
'leaderboard' |
Name of a hive in the system. |
'players' |
Name of a sorted set where the operation takes place. |
Response
[
[
1.0,
"Player B"
],
[
2.0,
"Player A"
],
[
3.0,
"Player F"
]
]
If the withScores
parameter is set to false
or is not present, the response does not include the scores:
[
"Player B",
"Player A",
"Player F"
]
Codeless Reference¶
where:
Argument | Description |
---|---|
hive name |
Name of a hive where the operation is performed. |
key name |
Key name identifying a sorted set. |
from/to |
The inclusive range of ranks (positions) of elements, between which the items are requested (the maximum for returning elements is the difference between these two parameters which cannot be bigger than 10000); The to parameter can also be a negative number indicating offset from the end of the sorted set, with -1 being the last element of the sorted set, -2 the penultimate element, and so on. |
with score |
Set this parameter to true if you want to return values with their scores. |
reverse |
When set to true , items are sorted in ascending order. If set to false , items are ordered in descending order. |
This operation returns values for a range of rank numbers. A rank in a sorted set determines the position of an element. For more information about the rank, refer to the Hive Overview section of this guide.
When the with scores
parameter is set to true
, the return value is a list of score-value pairs. Each pair is also a list of two elements - the score and the value. When the with scores
parameter is set to false
, the return value is a list of values.
Consider the following Sorted Set storage:
The example below retrieves values in the rank range starting from 0
to 2
from the "players"
sorted set.
The output will look as shown below after the Codeless logic runs: