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¶
Get range of values without scores
Backendless.Hive(hiveName).SortedSetStore(keyName).getRangeByRank(startRank,stopRank,reverse);
Get range of values with scores
Backendless.Hive(hiveName).SortedSetStore(keyName).getRangeWithScoresByRank(startRank,stopRank,reverse);
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. |
reverse |
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 getRangeWithScoresByRank
method is used, the return value is an array of score-value pairs. Each pair is also an array of two elements - the score and the value. When the withScores
parameter is set to false
, the return value is array of values.When the getRangeByRank
is used, the return value is an array of values.
Example¶
Get random values with scores
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.
Backendless.Hive("leaderboard").SortedSetStore("League1Players").getRangeWithScoresByRank(1, 4, true);
Get range of values without scores
In contrast to the last example, this returns an array of values.
Backendless.Hive("leaderboard").SortedSetStore("players").getRangeByRank(1,4,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 thegetRangeByRank
method is used, 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: