Skip to content

Commit 26ade92

Browse files
authored
Merge pull request #1543 from go-redis/fix/conn-hooks
Add hooks to Conn. Fixes #1539
2 parents 16afeeb + e99a392 commit 26ade92

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

redis.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ type conn struct {
719719
baseClient
720720
cmdable
721721
statefulCmdable
722+
hooks // TODO: inherit hooks
722723
}
723724

724725
// Conn is like Client, but its pool contains single connection.
@@ -743,7 +744,15 @@ func newConn(ctx context.Context, opt *Options, connPool pool.Pooler) *Conn {
743744
}
744745

745746
func (c *Conn) Process(ctx context.Context, cmd Cmder) error {
746-
return c.baseClient.process(ctx, cmd)
747+
return c.hooks.process(ctx, cmd, c.baseClient.process)
748+
}
749+
750+
func (c *Conn) processPipeline(ctx context.Context, cmds []Cmder) error {
751+
return c.hooks.processPipeline(ctx, cmds, c.baseClient.processPipeline)
752+
}
753+
754+
func (c *Conn) processTxPipeline(ctx context.Context, cmds []Cmder) error {
755+
return c.hooks.processTxPipeline(ctx, cmds, c.baseClient.processTxPipeline)
747756
}
748757

749758
func (c *Conn) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error) {

redis_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ var _ = Describe("Client", func() {
295295

296296
Expect(tm2).To(BeTemporally("==", tm))
297297
})
298+
299+
It("should Conn", func() {
300+
err := rdb.Conn(ctx).Get(ctx, "this-key-does-not-exist").Err()
301+
Expect(err).To(Equal(redis.Nil))
302+
})
298303
})
299304

300305
var _ = Describe("Client timeout", func() {

0 commit comments

Comments
 (0)