public static class AggregateArgs.SortBy extends Object implements AggregateArgs.PipelineOperation
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> properties) |
| Modifier and Type | Method and Description |
|---|---|
void |
build(CommandArgs<?,?> args)
Build the operation arguments into the command args.
|
AggregateArgs.SortBy |
max(long max) |
static AggregateArgs.SortBy |
of(AggregateArgs.SortProperty... properties)
Static factory method to create a SortBy instance with multiple properties.
|
static AggregateArgs.SortBy |
of(String property,
AggregateArgs.SortDirection direction)
Static factory method to create a SortBy instance with a single property.
|
AggregateArgs.SortBy |
withCount() |
public SortBy(List<AggregateArgs.SortProperty> properties)
public AggregateArgs.SortBy max(long max)
public AggregateArgs.SortBy withCount()
public static AggregateArgs.SortBy of(String property, AggregateArgs.SortDirection direction)
property - the property to sort bydirection - the sort direction@SafeVarargs public static AggregateArgs.SortBy of(AggregateArgs.SortProperty... properties)
properties - the properties to sort bypublic void build(CommandArgs<?,?> args)
AggregateArgs.PipelineOperationbuild in interface AggregateArgs.PipelineOperationargs - the command args to build intoCopyright © 2026 lettuce.io. All rights reserved.