1 Star 0 Fork 0

h79/goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
server.go 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2022-06-01 16:22 . init
package pool
import (
"context"
"sync"
"github.com/go-redis/redis/v8"
)
//Info 获取所有就节点信息
func (c *Client) Info(ctx context.Context, section ...string) (res map[string]string, err error) {
client, cErr := getClusterClient(c)
if cErr != nil {
return nil, cErr
}
res = make(map[string]string, 0)
locker := sync.RWMutex{}
err = client.ForEachShard(ctx, func(ctx context.Context, c *redis.Client) error {
defer locker.Unlock()
addr := c.Options().Addr
r, e := c.Info(ctx, section...).Result()
locker.Lock()
if e == nil {
res[addr] = r
} else {
res[addr] = e.Error()
}
return e
})
return res, err
}
//NodeInfo 获取单个节点的info
func (c *Client) NodeInfo(ctx context.Context, addr string, section ...string) (res string, err error) {
client, cErr := getClusterClient(c)
if cErr != nil {
return "", cErr
}
err = client.ForEachShard(ctx, func(ctx context.Context, c *redis.Client) (err error) {
if addr == c.Options().Addr {
res, err = c.Info(ctx, section...).Result()
}
return
})
return res, err
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.2.9

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385