代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。