// Author: simon (ynwdlxm@163.com) // Date: 2025/10/20 11:32 // Desc: 客户端连接工厂 package cluster import ( "context" "errors" pool "github.com/jolestar/go-commons-pool/v2" client_ "github.com/runningwater/go-redis/resp/client" ) type connectionFactory struct { Peer string // 节点地址 } func (c connectionFactory) MakeObject(ctx context.Context) (*pool.PooledObject, error) { client, err := client_.NewClient(c.Peer) if err != nil { return nil, err } client.Start() return pool.NewPooledObject(client), nil } func (c connectionFactory) DestroyObject(ctx context.Context, object *pool.PooledObject) error { client, ok := object.Object.(*client_.Client) if !ok { return errors.New("type mismatch") } client.Stop() return nil } func (c connectionFactory) ValidateObject(ctx context.Context, object *pool.PooledObject) bool { return true } func (c connectionFactory) ActivateObject(ctx context.Context, object *pool.PooledObject) error { return nil } func (c connectionFactory) PassivateObject(ctx context.Context, object *pool.PooledObject) error { return nil }