1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

Close single conn connection pool

This commit is contained in:
Patrick White
2019-08-01 14:59:53 -07:00
parent 0cf98f9217
commit efa4a78883
2 changed files with 21 additions and 2 deletions

View File

@ -1,9 +1,14 @@
package pool
import "context"
import (
"context"
"github.com/go-redis/redis/internal"
)
type SingleConnPool struct {
cn *Conn
cn *Conn
cnClosed bool
}
var _ Pooler = (*SingleConnPool)(nil)
@ -23,6 +28,9 @@ func (p *SingleConnPool) CloseConn(*Conn) error {
}
func (p *SingleConnPool) Get(ctx context.Context) (*Conn, error) {
if p.cnClosed {
return nil, internal.ErrSingleConnPoolClosed
}
return p.cn, nil
}
@ -36,9 +44,13 @@ func (p *SingleConnPool) Remove(cn *Conn) {
if p.cn != cn {
panic("p.cn != cn")
}
p.cnClosed = true
}
func (p *SingleConnPool) Len() int {
if p.cnClosed {
return 0
}
return 1
}