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

Backendless.Hive(hiveName).SortedSetStore().intersection(keyNames);

where:

Argument                Description
hiveName Name of a hive where the operation is performed. String value.
keyNames A set containing key names each identifying a sorted-set. Must be a set of string values.

Return Value

An 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.

Set<String> keyNames = new HashSet<>();
keyNames.add( "League1Players" );
keyNames.add( "League2Players" );

Backendless.Hive("leaderboard").SortedSetStore().intersection(keyNames);

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