redis/internal/pool/pool_single.go

68 lines
1.0 KiB
Go
Raw Normal View History

package pool
2019-08-02 00:59:53 +03:00
import (
"context"
"github.com/go-redis/redis/internal"
)
2019-06-04 14:05:29 +03:00
type SingleConnPool struct {
2019-08-02 00:59:53 +03:00
cn *Conn
cnClosed bool
}
var _ Pooler = (*SingleConnPool)(nil)
func NewSingleConnPool(cn *Conn) *SingleConnPool {
return &SingleConnPool{
cn: cn,
}
}
2019-06-14 16:00:03 +03:00
func (p *SingleConnPool) NewConn(context.Context) (*Conn, error) {
panic("not implemented")
}
func (p *SingleConnPool) CloseConn(*Conn) error {
panic("not implemented")
}
func (p *SingleConnPool) Get(ctx context.Context) (*Conn, error) {
2019-08-02 00:59:53 +03:00
if p.cnClosed {
return nil, internal.ErrSingleConnPoolClosed
}
2018-05-28 17:27:24 +03:00
return p.cn, nil
}
2018-05-28 17:27:24 +03:00
func (p *SingleConnPool) Put(cn *Conn) {
if p.cn != cn {
panic("p.cn != cn")
}
}
2018-05-28 17:27:24 +03:00
func (p *SingleConnPool) Remove(cn *Conn) {
if p.cn != cn {
panic("p.cn != cn")
}
2019-08-02 00:59:53 +03:00
p.cnClosed = true
}
func (p *SingleConnPool) Len() int {
2019-08-02 00:59:53 +03:00
if p.cnClosed {
return 0
}
return 1
}
2018-05-28 17:27:24 +03:00
func (p *SingleConnPool) IdleLen() int {
return 0
}
func (p *SingleConnPool) Stats() *Stats {
return nil
}
func (p *SingleConnPool) Close() error {
return nil
}