Skip to content

Difference

Description

This operation finds the difference between the primary (first) set and all other specified sets. To find the difference, the operation subtracts identical values across multiple sorted sets and returning the remainder (i.e. the difference) in a new sorted set. The first sorted set in the request is considered the main sorted set whose remainder is left after the subtraction operation.

Important

The subtraction is performed only on values - scores are not checked for equality.

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/difference

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 names of the sorted sets as string values. The first sorted set in the array is the main one - all "subtraction" operations are performed on that sorted set.

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

Response Body

A JSON array of arrays. Each element of the response array is another array containing a score/value pair.

Example

Consider the following sorted sets:

sorted-set-difference

The example below finds the difference between the "League1Players" and the "League2Players" sorted sets:

curl --location --request POST "https://xxxx.backendless.app/api/hive/leaderboard/sorted-set/action/difference" \  
        --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"  
  ]  
]

Codeless Reference

sorted_set_api_difference

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 lists. Each element of the response list is another list containing a score/value pair.

Consider the following Sorted Set storage:
sorted_set_api_example_union_difference_intersection

The example below subtracts identical values across the specified sorted sets (i.e. "players", "players_2") and returns the remainder (i.e. the difference) in a new sorted set. The first sorted set in the request is considered the main sorted set whose remainder is left after the subtraction operation.
sorted_set_api_example_difference

The output will look as shown below after the Codeless logic runs:
sorted_set_api_example_difference_2