summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-redis/redis/redis_context.go
blob: c00e505f6cc9d677c3679eea9e5c41769d48d062 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// +build go1.7

package redis

import (
	"context"

	"github.com/go-redis/redis/internal/pool"
)

type baseClient struct {
	connPool pool.Pooler
	opt      *Options

	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 *Client) Context() context.Context {
	if c.ctx != nil {
		return c.ctx
	}
	return context.Background()
}

func (c *Client) WithContext(ctx context.Context) *Client {
	if ctx == nil {
		panic("nil context")
	}
	c2 := c.copy()
	c2.ctx = ctx
	return c2
}