Length with a Query¶
Description¶
This operation returns the number of items with a score a range between the specified min and max values.
Method¶
[[[Backendless.shared hive:(NSString *)hiveName] sortedSetStore:(NSString *)keyName] countBetweenScoresWithOptions:(SortedSetFilter *)filter responseHandler:^(NSInteger)responseHandler errorHandler:^(Fault *)errorHandler];
Backendless.shared.hive(hiveName: String).sortedSetStore(keyName: String).countBetweenScores(options: SortedSetFilter, responseHandler: ((Int) -> Void)!, errorHandler: ((Fault) -> Void)!)
where:
Argument | Description |
---|---|
hiveName |
Name of a hive where the operation is performed. String value. |
keyName |
Key name identifying a sorted-set. String value. |
minScore/maxScore |
Optional parameters. Score values between which the items are requested. To control whether the specified values are included or excluded from the range, use the minBound /maxBound parameters. |
minBound/maxBound |
Optional parameters. Available options are (all as string values): 'Include' - Includes value specified in the corresponding minScore /maxScore parameter into the range.'Exclude' - Excludes value specified in the corresponding minScore /maxScore parameter from the range.'Infinity' - Ignores the corresponding minScore /maxScore parameter and includes all consecutive score values that come before/after the defined score range. For example, if minBound is set to Infinity and maxScore is set to 5, the query will include all values with scores less than 5. |
options |
Represents the SortedSetFilter object, consisting of parameters that control the behavior of this operation. See the description below. |
SortedSetFilter is an object with the following structure:
@interface SortedSetFilter : NSObject
@property (nonatomic) double minScore;
@property (nonatomic) double maxScore;
@property (nonatomic) enum SortedSetBound minBound;
@property (nonatomic) enum SortedSetBound maxBound;
@end
@objcMembers public class SortedSetFilter: NSObject {
public var minScore = 0.0
public var maxScore = 0.0
public var minBound = SortedSetBound.include
public var maxBound = SortedSetBound.include
}
where:
Argument | Description |
---|---|
minScore/maxScore |
Minimum and maximum value of the scores to identify the items to delete. To control whether the specified score values are included or excluded from the range, use the minBound /maxBound parameters. |
minBound/maxBound |
Optional parameters. Available options are: Include - Includes value specified in the corresponding minScore /maxScore parameter into the range.Exclude - Excludes value specified in the corresponding minScore /maxScore parameter from the range.Infinity - Ignores the corresponding minScore /maxScore parameter and includes all consecutive score values that come before/after the defined score range. For example, if minBound is set to Infinity and maxScore is set to 5, the query will include all values with scores less than 5. |
Return Value¶
Number of items with a score and range between the specified min and max values.
Example¶
The example gets the count of items with scores between 1
and to 20
. The minBound
parameter is Include
, as a result the score of 1
is included in the range. The maxBound
parameter is set to Exclude
, as a result, the value of 20
is excluded from the range.
SortedSetFilter *options = [SortedSetFilter new];
options.minScore = 0;
options.maxScore = 20;
options.minBound = SortedSetBoundInclude;
options.maxBound = SortedSetBoundExclude;
[[[Backendless.shared hive:@"leaderboard"] sortedSetStore:@"players"] countBetweenScoresWithOptions:options responseHandler:^(NSInteger response) {
// handle response
} errorHandler:^(Fault *fault) {
// handle error
}];
let options = SortedSetFilter()
options.minScore = 0
options.maxScore = 20
options.minBound = .include
options.maxBound = .exclude
Backendless.shared.hive("leaderboard").sortedSetStore("players").countBetweenScores(options: options, responseHandler: { response in
// handle response
}, errorHandler: { fault in
// handle error
})
where:
Argument | Description |
---|---|
"leaderboard" |
Name of a hive where the operation is performed. |
"players" |
Key name identifying a sorted set. |
Codeless Reference¶
where:
Argument | Description |
---|---|
hive name |
Name of a hive where the operation is performed. |
key name |
Key name identifying a sorted set. |
min/max score |
Specify the minimum and maximum score values to form a range. Refer to description above. |
min/max bound |
Parameters that control the presence of the first and last values in the range. Each parameter has three options:Include - Includes value specified in the corresponding min score /max score parameter into the range. Exclude - Excludes value specified in the corresponding min score /max score parameter from the range.Infinity - Ignores the corresponding min score /max score parameter and includes all consecutive score values that come before/after the defined score range. For example, if min bound is set to Infinity and max score is set to 5, the query will include all values with scores less than 5.These parameters default to Include . |
Returns the number of items with a score and range between the specified min and max values.
Consider the following Sorted Set storage:
The example below retrieves the count of items with scores between 0
and to 5
. Considering the sorted set (i.e. "players"
) presented above only two values are counted since "Bobby"
has the score of 3
and "John"
has the score of 5
; These two values fall into the specified score range.
The output will look as shown below after the Codeless logic runs.