(ctx context.Context)
| 66 | } |
| 67 | |
| 68 | func (p *StickyConnPool) Get(ctx context.Context) (*Conn, error) { |
| 69 | // In worst case this races with Close which is not a very common operation. |
| 70 | for i := 0; i < 1000; i++ { |
| 71 | switch atomic.LoadUint32(&p.state) { |
| 72 | case stateDefault: |
| 73 | cn, err := p.pool.Get(ctx) |
| 74 | if err != nil { |
| 75 | return nil, err |
| 76 | } |
| 77 | if atomic.CompareAndSwapUint32(&p.state, stateDefault, stateInited) { |
| 78 | return cn, nil |
| 79 | } |
| 80 | p.pool.Remove(ctx, cn, ErrClosed) |
| 81 | case stateInited: |
| 82 | if err := p.badConnError(); err != nil { |
| 83 | return nil, err |
| 84 | } |
| 85 | cn, ok := <-p.ch |
| 86 | if !ok { |
| 87 | return nil, ErrClosed |
| 88 | } |
| 89 | return cn, nil |
| 90 | case stateClosed: |
| 91 | return nil, ErrClosed |
| 92 | default: |
| 93 | panic("not reached") |
| 94 | } |
| 95 | } |
| 96 | return nil, fmt.Errorf("redis: StickyConnPool.Get: infinite loop") |
| 97 | } |
| 98 | |
| 99 | func (p *StickyConnPool) Put(ctx context.Context, cn *Conn) { |
| 100 | defer func() { |
nothing calls this directly
no test coverage detected