Skip to content

Intersection

Description

This operation finds and returns identical values between two or more sorted 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/intersection

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

The request body must be a JSON array containing key names identifying sorted sets for the operation:

["sorted_set_1", "sorted_set_2", ...]

Response Body

A JSON array of values that are present in all referenced sorted sets. 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:
sorted-set-difference

The example below finds identical values in the "League1Players" and "League2Players" sorted sets. Note that the score of identical values found in the specified sorted sets is summed.

curl --location --request POST "https://xxxx.backendless.app/api/hive/leaderboard/sorted-set/action/intersection" \  
  --header 'Content-Type: application/json' \  
  --data-raw '[  
    "League1Players", "League2Players"  
 ]']

where:

Argument                Description
leaderboard Name of the hive in the system.

Response

[  
  [  
    24,  
    "Frank"  
  ],  
  [  
    26,  
    "Dave"  
  ],  
  [  
    28,  
    "Bobby"  
  ]  
]

Codeless Reference

sorted_set_api_intersection

where:

Argument                Description
hive name Name of a hive where the operation is performed.
key name A list containing key names identifying unique sorted sets.

Returns a list of values that are present in all referenced sorted sets. The structure of the response is a list of list. 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:
sorted_set_api_example_union_difference_intersection

The example below finds identical score-value pairs in the following sorted sets: "players" and "players_2".
sorted_set_api_example_intersection

The output will look as shown below after the Codeless logic runs. Note that the score of identical values found in the specified sorted sets is summed.
sorted_set_api_example_intersection_2