1 Star 0 Fork 0

fkil555/gin-extend

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cache_manager.go 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
fkil555 提交于 2023-10-26 09:15 . up
package gredis
import (
"context"
"github.com/go-redis/redis"
)
// CACHE总管理器
type CACHEManager struct {
GroupMap map[string]*CACHEGroup
}
func NewRedis(config *CACHEConf) (cacheMgr *CACHEManager, err error) {
cacheMgr = &CACHEManager{
GroupMap: make(map[string]*CACHEGroup),
}
if config == nil || config.GroupConfList == nil {
return
}
// 按Name索引每一个CACHEGroup
groupConfList := config.GroupConfList
for i := 0; i < len(groupConfList); i++ {
var cacheGroup *CACHEGroup
if cacheGroup, err = newCACHEGroup(&groupConfList[i]); err != nil {
return
}
cacheMgr.GroupMap[groupConfList[i].Name] = cacheGroup
}
GERedis = cacheMgr
return
}
// 获取redis主从实例
func (cacheMgr *CACHEManager) Instance(ctx context.Context, name string, optionFuncs ...OptionFunc) (cacheClient *CacheClient, err error) {
cacheGroup, existed := cacheMgr.GroupMap[name]
if !existed {
err = ERR_CACHE_GROUP_NOT_FOUND
return
}
cacheClient = newCacheClient(ctx, cacheGroup, optionFuncs...)
return
}
// 获取redis集群实例
func (cacheMgr *CACHEManager) InstanceCluster(ctx context.Context, name string) (client *redis.ClusterClient, err error) {
cacheGroup, existed := cacheMgr.GroupMap[name]
if !existed {
err = ERR_CACHE_GROUP_NOT_FOUND
return
}
client, err = cacheGroup.ChooseClusterConn(ctx)
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fkil555/gin-extend.git
git@gitee.com:fkil555/gin-extend.git
fkil555
gin-extend
gin-extend
v0.0.5

搜索帮助

0d507c66 1850385 C8b1a773 1850385