当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
12 Star 29 Fork 4

letsfire / redigo
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cluster.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
letsfire 提交于 2019-01-26 20:05 . add mode String interface
package cluster
import (
"github.com/gomodule/redigo/redis"
"github.com/letsfire/redigo/mode"
"github.com/letsfire/redisc"
)
type clusterMode struct {
rc *redisc.Cluster
}
func (cm *clusterMode) GetConn() redis.Conn {
return cm.rc.Get()
}
func (cm *clusterMode) NewConn() (redis.Conn, error) {
return cm.rc.Dial()
}
func (cm *clusterMode) String() string {
return "cluster"
}
var _ mode.IMode = &clusterMode{}
func New(optFuncs ...OptFunc) *clusterMode {
opts := options{
nodes: []string{
"127.0.0.1:30001", "127.0.0.1:30002", "127.0.0.1:30003",
"127.0.0.1:30004", "127.0.0.1:30005", "127.0.0.1:30006",
},
dialOpts: mode.DefaultDialOpts(),
poolOpts: mode.DefaultPoolOpts(),
}
for _, optFunc := range optFuncs {
optFunc(&opts)
}
rc := &redisc.Cluster{
StartupNodes: opts.nodes,
DialOptions: opts.dialOpts,
CreatePool: func(address string, options ...redis.DialOption) (*redis.Pool, error) {
pool := &redis.Pool{
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", address, options...)
},
}
for _, poolOptFunc := range opts.poolOpts {
poolOptFunc(pool)
}
return pool, nil
},
}
return &clusterMode{rc: rc}
}
Go
1
https://gitee.com/letsfire/redigo.git
git@gitee.com:letsfire/redigo.git
letsfire
redigo
redigo
v1.0.1

搜索帮助

53164aa7 5694891 3bd8fe86 5694891