mirror of
https://github.com/redis/go-redis.git
synced 2026-10-28 16:35:06 +08:00
Both FT.AGGREGATE examples tell the reader to set `UnstableResp3: true` to use RESP3: example/search-aggregate-steps/README.md:15-17 example/search-aggregate-collect/README.md:15-18 That advice is stale in two ways. `Options.UnstableResp3` is deprecated and documented as a no-op (`options.go:448-451`, and the same note on `universal.go`, `osscluster.go`, `ring.go`, `sentinel.go`); README.md:536-543 says plainly that "new code should not set it". Grepping the package shows the field is only ever copied between option structs (`universal.go:291`, `osscluster.go:514`, `ring.go:276`, `sentinel.go:255`) or assigned from a URL (`sentinel.go:507`) — nothing reads it, so following the advice would change nothing. The stated reason is also gone: RediSearch RESP3 parsing has been stable since v9.20, which is why no flag is needed. The examples still construct their client with `Protocol: 2` (`search-aggregate-steps/main.go:25`, `search-aggregate-collect/main.go:29`); that choice is left alone, only the justification is corrected.
FT.AGGREGATE step-based pipeline example
This example demonstrates FTAggregateOptions.Steps, which lets LOAD,
APPLY, GROUPBY and SORTBY appear multiple times in any order in an
FT.AGGREGATE pipeline.
The main motivation is shard-level trimming: running a SORTBY ... MAX N
before a GROUPBY so each shard only ships its top-N rows onward.
Prerequisites
A Redis instance with the Search module loaded (Redis 8+, or Redis Stack)
listening on localhost:6379.
The client is configured with Protocol: 2. RESP3 needs no extra flag for
FT.AGGREGATE: its response is parsed into the same typed results on both
protocols.
Run
go run .
The example:
- Creates an index
idx:productsover hashes prefixed withproduct:. - Seeds 10 products with
category,brand,price,quantity,rating. - Runs three aggregations:
- Trim before GROUPBY —
SORTBY @rating DESC MAX 5→GROUPBY @category→SORTBY @price_total DESC. - Multi-stage pipeline —
LOAD→LOAD→APPLY→SORTBY MAX→GROUPBY→APPLY→SORTBY. - AggregateBuilder — the same first query expressed via the fluent
NewAggregateBuilderAPI.
- Trim before GROUPBY —