Skip to content

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

Backendless.Hive( hiveName ).SortedSetStore.union( keyNames ): Promise<values>;

where:

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

Return Value

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

sorted-set-difference

The example below retrieves a union of values from the sample sorted sets shown above:

await Backendless.Hive( 'leaderboard' ).SortedSetStore.union( [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

sorted_set_api_union

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:
sorted_set_api_example_union_difference_intersection

The example below retrieves a union of values from the sample sorted sets shown above:
sorted_set_api_example_union

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