代码拉取完成,页面将自动刷新
package redis
import (
"fmt"
"gitee.com/go-ultra/gou/core/logx"
red "github.com/go-redis/redis/v8"
)
// ClosableNode interface represents a closable redis node.
type ClosableNode interface {
RedisNode
Close()
}
// CreateBlockingNode returns a ClosableNode.
func CreateBlockingNode(r *Redis) (ClosableNode, error) {
timeout := readWriteTimeout + blockingQueryTimeout
switch r.Type {
case NodeType:
client := red.NewClient(&red.Options{
Addr: r.Addr,
Password: r.Pass,
DB: defaultDatabase,
MaxRetries: maxRetries,
PoolSize: 1,
MinIdleConns: 1,
ReadTimeout: timeout,
})
return &clientBridge{client}, nil
case ClusterType:
client := red.NewClusterClient(&red.ClusterOptions{
Addrs: []string{r.Addr},
Password: r.Pass,
MaxRetries: maxRetries,
PoolSize: 1,
MinIdleConns: 1,
ReadTimeout: timeout,
})
return &clusterBridge{client}, nil
default:
return nil, fmt.Errorf("unknown redis type: %s", r.Type)
}
}
type (
clientBridge struct {
*red.Client
}
clusterBridge struct {
*red.ClusterClient
}
)
func (bridge *clientBridge) Close() {
if err := bridge.Client.Close(); err != nil {
logx.Errorf("Error occurred on close redis client: %s", err)
}
}
func (bridge *clusterBridge) Close() {
if err := bridge.ClusterClient.Close(); err != nil {
logx.Errorf("Error occurred on close redis cluster: %s", err)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。