Skip to content

Commit 791ca8d

Browse files
authored
Merge branch 'master' into fix/race_slice_ring_client
2 parents 8d2f30d + 196fc9b commit 791ca8d

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

redis.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ type (
4141
)
4242

4343
type hooksMixin struct {
44-
hooksMu *sync.Mutex
44+
hooksMu *sync.RWMutex
4545

4646
slice []Hook
4747
initial hooks
4848
current hooks
4949
}
5050

5151
func (hs *hooksMixin) initHooks(hooks hooks) {
52-
hs.hooksMu = new(sync.Mutex)
52+
hs.hooksMu = new(sync.RWMutex)
5353
hs.initial = hooks
5454
hs.chain()
5555
}
@@ -151,7 +151,7 @@ func (hs *hooksMixin) clone() hooksMixin {
151151
clone := *hs
152152
l := len(clone.slice)
153153
clone.slice = clone.slice[:l:l]
154-
clone.hooksMu = new(sync.Mutex)
154+
clone.hooksMu = new(sync.RWMutex)
155155
return clone
156156
}
157157

@@ -176,7 +176,14 @@ func (hs *hooksMixin) withProcessPipelineHook(
176176
}
177177

178178
func (hs *hooksMixin) dialHook(ctx context.Context, network, addr string) (net.Conn, error) {
179-
return hs.current.dial(ctx, network, addr)
179+
// Access to hs.current is guarded by a read-only lock since it may be mutated by AddHook(...)
180+
// while this dialer is concurrently accessed by the background connection pool population
181+
// routine when MinIdleConns > 0.
182+
hs.hooksMu.RLock()
183+
current := hs.current
184+
hs.hooksMu.RUnlock()
185+
186+
return current.dial(ctx, network, addr)
180187
}
181188

182189
func (hs *hooksMixin) processHook(ctx context.Context, cmd Cmder) error {

search_commands.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,8 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
574574
if options.SortByMax > 0 {
575575
queryArgs = append(queryArgs, "MAX", options.SortByMax)
576576
}
577-
if options.LimitOffset > 0 {
578-
queryArgs = append(queryArgs, "LIMIT", options.LimitOffset)
579-
}
580-
if options.Limit > 0 {
581-
queryArgs = append(queryArgs, options.Limit)
577+
if options.LimitOffset >= 0 && options.Limit > 0 {
578+
queryArgs = append(queryArgs, "LIMIT", options.LimitOffset, options.Limit)
582579
}
583580
if options.Filter != "" {
584581
queryArgs = append(queryArgs, "FILTER", options.Filter)
@@ -773,11 +770,8 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
773770
if options.SortByMax > 0 {
774771
args = append(args, "MAX", options.SortByMax)
775772
}
776-
if options.LimitOffset > 0 {
777-
args = append(args, "LIMIT", options.LimitOffset)
778-
}
779-
if options.Limit > 0 {
780-
args = append(args, options.Limit)
773+
if options.LimitOffset >= 0 && options.Limit > 0 {
774+
args = append(args, "LIMIT", options.LimitOffset, options.Limit)
781775
}
782776
if options.Filter != "" {
783777
args = append(args, "FILTER", options.Filter)

search_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,11 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
616616
res, err = client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result()
617617
Expect(err).NotTo(HaveOccurred())
618618
Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("b"))
619+
620+
options = &redis.FTAggregateOptions{SortBy: []redis.FTAggregateSortBy{{FieldName: "@t1"}}, Limit: 1, LimitOffset: 0}
621+
res, err = client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result()
622+
Expect(err).NotTo(HaveOccurred())
623+
Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("a"))
619624
})
620625

621626
It("should FTAggregate load ", Label("search", "ftaggregate"), func() {

0 commit comments

Comments
 (0)