1 Star 0 Fork 0

Go Ultra / Go Ultra Framework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
redisblockingnode.go 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
vhake 提交于 2022-05-17 11:22 . init project
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)
}
}
Go
1
https://gitee.com/go-ultra/gou.git
git@gitee.com:go-ultra/gou.git
go-ultra
gou
Go Ultra Framework
v0.0.1

搜索帮助