| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- // 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
- }
|