Union¶
Description¶
This operation creates a union of values from the specified sorted sets. A union is a set made by combining the elements of two or more sets. When a value appears in more than one input sorted set, the resulting score is a sum of the scores from each sorted set.
Method¶
POST
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/action/union
where:
Argument | Description |
---|---|
[hive-name] |
Name of a hive where the operation is performed. |
Request Headers¶
Content-Type: application/json:
where:
Argument | Description |
---|---|
Content-Type |
Must be set to application/json . This header is mandatory. |
Request Body¶
A JSON array containing key names identifying sorted sets for the operation:
["sorted_set_1", "sorted_set_2", ...]
Response Body¶
A JSON array of combined values from all input sorted sets (duplicates excluded). The structure of the response is an array of arrays. Each individual element of the top level array is an array consisting of two elements - score and value. The score is the sum of all individual scores for the corresponding values from all referenced sorted sets.
Example¶
Consider the following sorted sets:
The example below retrieves a union of values from the sample sorted sets shown above:
curl --location --request POST "https://xxxx.backendless.app/api/hive/leaderboard/sorted-set/action/union" \
--header 'Content-Type: application/json' \
--data-raw '[
"League1Players", "League2Players"
]']
where:
Argument | Description |
---|---|
leaderboard |
Name of the hive in the system. |
Response
[
[
11,
"Charlie"
],
[
13,
"Adam"
],
[
24,
"Frank"
],
[
26,
"Dave"
],
[
28,
"Bobby"
]
]
Codeless Reference¶
where:
Argument | Description |
---|---|
hive name |
Name of a hive where the operation is performed. |
key names |
A list containing key names identifying unique sorted sets. |
Returns a list of combined values from all input sorted sets (duplicates excluded). The structure of the response is a list of lists. Each individual element of the top level list is a list consisting of two elements - score and value. The score is the sum of all individual scores for the corresponding values from all referenced sorted sets.
Consider the following Sorted Set storage:
The example below retrieves a union of values from the sample sorted sets shown above:
The output will look as shown below after the Codeless logic runs. For identical values found in the specified sorted sets the score is summed.