1
0
mirror of https://github.com/redis/go-redis.git synced 2025-04-17 20:17:02 +03:00

use limit when limitoffset is zero (#3275)

This commit is contained in:
Nedyalko Dyakov 2025-02-14 13:07:39 +02:00 committed by GitHub
parent 9db1286414
commit 196fc9b21a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 10 deletions

View File

@ -574,11 +574,8 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
if options.SortByMax > 0 { if options.SortByMax > 0 {
queryArgs = append(queryArgs, "MAX", options.SortByMax) queryArgs = append(queryArgs, "MAX", options.SortByMax)
} }
if options.LimitOffset > 0 { if options.LimitOffset >= 0 && options.Limit > 0 {
queryArgs = append(queryArgs, "LIMIT", options.LimitOffset) queryArgs = append(queryArgs, "LIMIT", options.LimitOffset, options.Limit)
}
if options.Limit > 0 {
queryArgs = append(queryArgs, options.Limit)
} }
if options.Filter != "" { if options.Filter != "" {
queryArgs = append(queryArgs, "FILTER", options.Filter) queryArgs = append(queryArgs, "FILTER", options.Filter)
@ -773,11 +770,8 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
if options.SortByMax > 0 { if options.SortByMax > 0 {
args = append(args, "MAX", options.SortByMax) args = append(args, "MAX", options.SortByMax)
} }
if options.LimitOffset > 0 { if options.LimitOffset >= 0 && options.Limit > 0 {
args = append(args, "LIMIT", options.LimitOffset) args = append(args, "LIMIT", options.LimitOffset, options.Limit)
}
if options.Limit > 0 {
args = append(args, options.Limit)
} }
if options.Filter != "" { if options.Filter != "" {
args = append(args, "FILTER", options.Filter) args = append(args, "FILTER", options.Filter)

View File

@ -616,6 +616,11 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
res, err = client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result() res, err = client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("b")) Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("b"))
options = &redis.FTAggregateOptions{SortBy: []redis.FTAggregateSortBy{{FieldName: "@t1"}}, Limit: 1, LimitOffset: 0}
res, err = client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("a"))
}) })
It("should FTAggregate load ", Label("search", "ftaggregate"), func() { It("should FTAggregate load ", Label("search", "ftaggregate"), func() {