From c2fb5132c003876e045ef1809112e6b6774e7e6f Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Wed, 7 Mar 2018 13:50:14 +0200 Subject: [PATCH] Cleanup context implementation --- cluster.go | 5 +++++ redis.go | 12 +++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cluster.go b/cluster.go index 4175b64..89f1e9a 100644 --- a/cluster.go +++ b/cluster.go @@ -592,6 +592,11 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient { return c } +func (c *ClusterClient) copy() *ClusterClient { + cp := *c + return &cp +} + // Options returns read-only Options that were used to create the client. func (c *ClusterClient) Options() *ClusterOptions { return c.opt diff --git a/redis.go b/redis.go index 7f5ac5f..e0b6464 100644 --- a/redis.go +++ b/redis.go @@ -24,16 +24,14 @@ func SetLogger(logger *log.Logger) { } type baseClient struct { - connPool pool.Pooler opt *Options + connPool pool.Pooler process func(Cmder) error processPipeline func([]Cmder) error processTxPipeline func([]Cmder) error onClose func() error // hook called when client is closed - - ctx context.Context } func (c *baseClient) init() { @@ -349,6 +347,8 @@ func (c *baseClient) txPipelineReadQueued(cn *pool.Conn, cmds []Cmder) error { type Client struct { baseClient cmdable + + ctx context.Context } func newClient(opt *Options, pool pool.Pooler) *Client { @@ -386,10 +386,8 @@ func (c *Client) WithContext(ctx context.Context) *Client { } func (c *Client) copy() *Client { - c2 := new(Client) - *c2 = *c - c2.cmdable.setProcessor(c2.Process) - return c2 + cp := *c + return &cp } // Options returns read-only Options that were used to create the client.