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

DELETE

Endpoint URL

Important

Make sure to replace xxxx in the domain name in the request specification below to the one assigned to your application.

https://xxxx.backendless.app/api/hive/[hive-name]/sorted-set/[key]/delete-by-rank?startRank=[startRank]&stopRank=[stopRank]

where:

Argument                Description
[hive-name] Name of a hive where the operation is performed.
[key] Key name identifying a sorted set.
[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=-3 and stopRank=-1 will delete last three items in the sorted set.

Request Headers

None.

Request Body

None.

Response Body

The number of deleted sorted set elements.

Example

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

curl --location --request DELETE "https://xxxx.backendless.app/api/hive/leaderboard/sorted-set/players/delete-by-rank?startRank=3&stopRank=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