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:
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user