Skip to content

Delete Values By Rank Range

Description

This operation removes all items with rank between start and stop. Both start and stop ranks are zero-based indexes with the zero rank assigned to an item with the lowest score. For more information about the rank, refer to the Hive Overview section of this guide.

Method

Backendless.Hive( hiveName ).SortedSetStore( keyName ).deleteValuesByRank( startRank, stopRank ): Promise<number>;

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 Start and end values that define a rank range. Values that fall within the range are deleted by the operation. Rank values can be expressed as negative numbers. The value of -1 represents the last item in the sorted set, The value of -2 is the second to last item and so on. When using negative rank values, both startRank and stopRank parameters must be negative. For example startRank of -3 and stopRank of -1 will delete last three items in the sorted set.

Return Value

The number of deleted sorted set elements.

Example

The example below deletes items in the range starting from rank 3 to 8:

await Backendless.Hive( 'leaderboard' ).SortedSetStore( 'players' ).deleteValuesByRank( 3, 8 )

where:

Argument                Description
'leaderboard'  Name of a hive where the operation is performed.
'players'  A name of the sorted set to delete multiple score-value pairs.

Codeless Reference

sorted_set_api_delete_values_by_rank_range

where:

Argument                Description
hive name Name of a hive where the operation is performed.
key name Key name identifying a sorted set.
from/to Start and end values that define a rank range. Values that fall within the range are deleted by the operation. Rank values can be expressed as negative numbers. The value of -1 represents the last item in the sorted set, The value of -2 is the second to last item and so on. When using negative rank values, both from and to parameters must be negative. For example from of -3 and to of -1 will delete last three items in the sorted set.

Both start and stop ranks are zero-based indexes with the zero rank assigned to an item with the lowest score. For more information about the rank, refer to the Hive Overview section of this guide.

Returns the number of deleted items.

Consider the following Sorted Set storage:
sorted_set_api_example_all_blocks

The example below deletes values in the range starting from rank 0 to 1. Values are deleted from the "players" sorted set. Considering the sorted set presented above, only two values are delete since "Bobby" has the rank of 0 and "John" has the rank of 1.
sorted_set_api_example_delete_values_by_rank_range


The sorted set will look as shown below after the Codeless logic runs.
sorted_set_api_example_delete_values_by_rank_range_2