1 Star 2 Fork 3

kristas/booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
redis_cache.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
kristas 提交于 2021-04-10 00:37 . fix: bug fix
package redis_cache_impl
import (
"gitee.com/kristas/booting-go/framework/common/cache/cache_factory"
"gitee.com/kristas/booting-go/framework/core/bean"
"gitee.com/kristas/booting-go/framework/core/config_loader"
"gitee.com/kristas/booting-go/framework/logging"
"github.com/garyburd/redigo/redis"
"github.com/sirupsen/logrus"
)
func init() {
cache_factory.Register("redis", new(RedisCache))
}
type RedisCache struct {
bean.DefaultBean
cache_factory.DefaultCacheImpl
conn redis.Conn
}
type RedisConfig struct {
Host string `json:"host" yaml:"host"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
DB int `json:"db" yaml:"db"`
}
func (r *RedisCache) Conn() (cache_factory.ICache, error) {
var config RedisConfig
config_loader.Inject("redis", &config)
conn, err := redis.Dial("tcp", config.Host)
if err != nil {
return nil, err
}
reply, err := conn.Do("select", config.DB)
if err != nil {
return nil, err
}
log := new(logrus.Logger)
logging.GetLog(log)
log.Info(reply)
if err != nil {
return nil, err
}
r.conn = conn
return r, nil
}
func (r *RedisCache) Save(key string, value interface{}) (interface{}, error) {
return r.conn.Do("set", key, value)
}
func (r *RedisCache) Del(key string) (interface{}, error) {
return r.conn.Do("del", key)
}
func (r *RedisCache) Get(key string) (interface{}, error) {
return r.conn.Do("get", key)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.1.5

搜索帮助