From e99a39201b71bbdd37e2b1c03ef9d9c45d910d64 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sat, 17 Oct 2020 15:21:09 +0300 Subject: [PATCH] Add hooks to Conn. Fixes #1539 --- redis.go | 11 ++++++++++- redis_test.go | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/redis.go b/redis.go index b70fef3..f3b3583 100644 --- a/redis.go +++ b/redis.go @@ -719,6 +719,7 @@ type conn struct { baseClient cmdable statefulCmdable + hooks // TODO: inherit hooks } // 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 { } func (c *Conn) Process(ctx context.Context, cmd Cmder) error { - return c.baseClient.process(ctx, cmd) + return c.hooks.process(ctx, cmd, c.baseClient.process) +} + +func (c *Conn) processPipeline(ctx context.Context, cmds []Cmder) error { + return c.hooks.processPipeline(ctx, cmds, c.baseClient.processPipeline) +} + +func (c *Conn) processTxPipeline(ctx context.Context, cmds []Cmder) error { + return c.hooks.processTxPipeline(ctx, cmds, c.baseClient.processTxPipeline) } func (c *Conn) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error) { diff --git a/redis_test.go b/redis_test.go index a9e88c9..32a3cbe 100644 --- a/redis_test.go +++ b/redis_test.go @@ -295,6 +295,11 @@ var _ = Describe("Client", func() { Expect(tm2).To(BeTemporally("==", tm)) }) + + It("should Conn", func() { + err := rdb.Conn(ctx).Get(ctx, "this-key-does-not-exist").Err() + Expect(err).To(Equal(redis.Nil)) + }) }) var _ = Describe("Client timeout", func() {