redis_context.go 529 B

1234567891011121314151617181920212223242526272829303132333435
  1. // +build go1.7
  2. package redis
  3. import (
  4. "context"
  5. "gopkg.in/redis.v5/internal/pool"
  6. )
  7. type baseClient struct {
  8. connPool pool.Pooler
  9. opt *Options
  10. process func(Cmder) error
  11. onClose func() error // hook called when client is closed
  12. ctx context.Context
  13. }
  14. func (c *Client) Context() context.Context {
  15. if c.ctx != nil {
  16. return c.ctx
  17. }
  18. return context.Background()
  19. }
  20. func (c *Client) WithContext(ctx context.Context) *Client {
  21. if ctx == nil {
  22. panic("nil context")
  23. }
  24. c2 := c.copy()
  25. c2.ctx = ctx
  26. return c2
  27. }