diff --git a/define.go b/define.go index 24f73ad..51073d1 100644 --- a/define.go +++ b/define.go @@ -84,3 +84,12 @@ type WrapperClient struct { func (wc *WrapperClient) GetClient() *clientv3.Client { return wc.client } + +// Close 关闭 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:38 2023/8/15 +func (wc *WrapperClient) Close() error { + return wc.GetClient().Close() +} diff --git a/init.go b/init.go index 9e9beb4..3d5f5ba 100644 --- a/init.go +++ b/init.go @@ -101,3 +101,21 @@ func (c *client) GetClientWithError(flag string) (*WrapperClient, error) { } return c.table[flag], nil } + +// RemoveClient 删除client连接 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:37 2023/8/15 +func (c *client) RemoveClient(flag string) { + c.lock.RLock() + defer c.lock.RUnlock() + if _, exist := c.table[flag]; !exist { + return + } + // 关闭连接 + _ = c.table[flag].Close() + // 清除实例 + delete(c.table, flag) + return +}