1
0
mirror of https://github.com/redis/go-redis.git synced 2025-08-01 16:06:54 +03:00

Add race test for big vals. Copy connection to avoid race with PubSub.

This commit is contained in:
Vladimir Mihailenco
2016-03-14 13:17:33 +02:00
parent 50b2689809
commit 46790aa060
22 changed files with 257 additions and 148 deletions

View File

@ -14,6 +14,8 @@ type StickyConnPool struct {
mx sync.Mutex
}
var _ Pooler = (*StickyConnPool)(nil)
func NewStickyConnPool(pool *ConnPool, reusable bool) *StickyConnPool {
return &StickyConnPool{
pool: pool,
@ -33,7 +35,7 @@ func (p *StickyConnPool) Get() (cn *Conn, isNew bool, err error) {
p.mx.Lock()
if p.closed {
err = errClosed
err = ErrClosed
return
}
if p.cn != nil {
@ -59,7 +61,7 @@ func (p *StickyConnPool) Put(cn *Conn) error {
defer p.mx.Unlock()
p.mx.Lock()
if p.closed {
return errClosed
return ErrClosed
}
if p.cn != cn {
panic("p.cn != cn")
@ -77,7 +79,7 @@ func (p *StickyConnPool) Replace(cn *Conn, reason error) error {
defer p.mx.Unlock()
p.mx.Lock()
if p.closed {
return errClosed
return nil
}
if p.cn == nil {
panic("p.cn == nil")
@ -112,7 +114,7 @@ func (p *StickyConnPool) Close() error {
defer p.mx.Unlock()
p.mx.Lock()
if p.closed {
return errClosed
return ErrClosed
}
p.closed = true
var err error
@ -126,3 +128,10 @@ func (p *StickyConnPool) Close() error {
}
return err
}
func (p *StickyConnPool) Closed() bool {
p.mx.Lock()
closed := p.closed
p.mx.Unlock()
return closed
}