public static class AggregateArgs.SortBy<K> extends Object implements AggregateArgs.PipelineOperation<K,Object>
Sorts the pipeline results up until the point of SORTBY, using a list of properties. By default, sorting is ascending, but ASC or DESC can be specified for each property.
{
@code
// Simple sort by single field
SortBy sortBy = SortBy.of("price", SortDirection.DESC);
// Sort with MAX optimization for top-N queries
SortBy topN = SortBy.of("score", SortDirection.DESC).max(100) // Only sort top 100 results
.withCount(); // Include accurate count
// Multiple sort criteria
SortBy multiSort = SortBy.of(new SortProperty<>("category", SortDirection.ASC),
new SortProperty<>("price", SortDirection.DESC));
}
Performance Note: Use max() for efficient top-N queries instead of sorting all results and then
using LIMIT.
| Constructor and Description |
|---|
SortBy(List<AggregateArgs.SortProperty<K>> properties) |
| Modifier and Type | Method and Description |
|---|---|
void |
build(CommandArgs<K,Object> args)
Build the operation arguments into the command args.
|
AggregateArgs.SortBy<K> |
max(long max) |
static <K> AggregateArgs.SortBy<K> |
of(AggregateArgs.SortProperty<K>... properties)
Static factory method to create a SortBy instance with multiple properties.
|
static <K> AggregateArgs.SortBy<K> |
of(K property,
AggregateArgs.SortDirection direction)
Static factory method to create a SortBy instance with a single property.
|
AggregateArgs.SortBy<K> |
withCount() |
public SortBy(List<AggregateArgs.SortProperty<K>> properties)
public AggregateArgs.SortBy<K> max(long max)
public AggregateArgs.SortBy<K> withCount()
public static <K> AggregateArgs.SortBy<K> of(K property, AggregateArgs.SortDirection direction)
K - Key typeproperty - the property to sort bydirection - the sort direction@SafeVarargs public static <K> AggregateArgs.SortBy<K> of(AggregateArgs.SortProperty<K>... properties)
K - Key typeproperties - the properties to sort bypublic void build(CommandArgs<K,Object> args)
AggregateArgs.PipelineOperationbuild in interface AggregateArgs.PipelineOperation<K,Object>args - the command args to build intoCopyright © 2025 lettuce.io. All rights reserved.