Skip to content

Commit 12b9efe

Browse files
authored
Merge branch 'master' into add-conn-pool-wait-stats
2 parents 588a71f + 6ddf278 commit 12b9efe

File tree

6 files changed

+67
-4
lines changed

6 files changed

+67
-4
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828

2929
steps:
3030
- name: Set up ${{ matrix.go-version }}
31-
uses: actions/setup-go@v4
31+
uses: actions/setup-go@v5
3232
with:
3333
go-version: ${{ matrix.go-version }}
3434

.github/workflows/doctests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929

3030
steps:
3131
- name: Set up ${{ matrix.go-version }}
32-
uses: actions/setup-go@v4
32+
uses: actions/setup-go@v5
3333
with:
3434
go-version: ${{ matrix.go-version }}
3535

.github/workflows/spellcheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
- name: Checkout
99
uses: actions/checkout@v4
1010
- name: Check Spelling
11-
uses: rojopolis/spellcheck-github-actions@0.34.0
11+
uses: rojopolis/spellcheck-github-actions@0.35.0
1212
with:
1313
config_path: .github/spellcheck-settings.yml
1414
task_name: Markdown

.github/workflows/stale-issues.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/stale@v8
15+
- uses: actions/stale@v9
1616
with:
1717
repo-token: ${{ secrets.GITHUB_TOKEN }}
1818
stale-issue-message: 'This issue is marked stale. It will be closed in 30 days if it is not updated.'

redis.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"net"
8+
"sync"
89
"sync/atomic"
910
"time"
1011

@@ -40,12 +41,15 @@ type (
4041
)
4142

4243
type hooksMixin struct {
44+
hooksMu *sync.Mutex
45+
4346
slice []Hook
4447
initial hooks
4548
current hooks
4649
}
4750

4851
func (hs *hooksMixin) initHooks(hooks hooks) {
52+
hs.hooksMu = new(sync.Mutex)
4953
hs.initial = hooks
5054
hs.chain()
5155
}
@@ -116,6 +120,9 @@ func (hs *hooksMixin) AddHook(hook Hook) {
116120
func (hs *hooksMixin) chain() {
117121
hs.initial.setDefaults()
118122

123+
hs.hooksMu.Lock()
124+
defer hs.hooksMu.Unlock()
125+
119126
hs.current.dial = hs.initial.dial
120127
hs.current.process = hs.initial.process
121128
hs.current.pipeline = hs.initial.pipeline
@@ -138,9 +145,13 @@ func (hs *hooksMixin) chain() {
138145
}
139146

140147
func (hs *hooksMixin) clone() hooksMixin {
148+
hs.hooksMu.Lock()
149+
defer hs.hooksMu.Unlock()
150+
141151
clone := *hs
142152
l := len(clone.slice)
143153
clone.slice = clone.slice[:l:l]
154+
clone.hooksMu = new(sync.Mutex)
144155
return clone
145156
}
146157

@@ -165,6 +176,8 @@ func (hs *hooksMixin) withProcessPipelineHook(
165176
}
166177

167178
func (hs *hooksMixin) dialHook(ctx context.Context, network, addr string) (net.Conn, error) {
179+
hs.hooksMu.Lock()
180+
defer hs.hooksMu.Unlock()
168181
return hs.current.dial(ctx, network, addr)
169182
}
170183

redis_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,53 @@ var _ = Describe("Hook", func() {
579579
Expect(cmd.Val()).To(Equal("Script and hook"))
580580
})
581581
})
582+
583+
var _ = Describe("Hook with MinIdleConns", func() {
584+
var client *redis.Client
585+
586+
BeforeEach(func() {
587+
options := redisOptions()
588+
options.MinIdleConns = 1
589+
client = redis.NewClient(options)
590+
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
591+
})
592+
593+
AfterEach(func() {
594+
err := client.Close()
595+
Expect(err).NotTo(HaveOccurred())
596+
})
597+
598+
It("fifo", func() {
599+
var res []string
600+
client.AddHook(&hook{
601+
processHook: func(hook redis.ProcessHook) redis.ProcessHook {
602+
return func(ctx context.Context, cmd redis.Cmder) error {
603+
res = append(res, "hook-1-process-start")
604+
err := hook(ctx, cmd)
605+
res = append(res, "hook-1-process-end")
606+
return err
607+
}
608+
},
609+
})
610+
client.AddHook(&hook{
611+
processHook: func(hook redis.ProcessHook) redis.ProcessHook {
612+
return func(ctx context.Context, cmd redis.Cmder) error {
613+
res = append(res, "hook-2-process-start")
614+
err := hook(ctx, cmd)
615+
res = append(res, "hook-2-process-end")
616+
return err
617+
}
618+
},
619+
})
620+
621+
err := client.Ping(ctx).Err()
622+
Expect(err).NotTo(HaveOccurred())
623+
624+
Expect(res).To(Equal([]string{
625+
"hook-1-process-start",
626+
"hook-2-process-start",
627+
"hook-2-process-end",
628+
"hook-1-process-end",
629+
}))
630+
})
631+
})

0 commit comments

Comments
 (0)