@@ -12,8 +12,10 @@ require ( | |||||
require ( | require ( | ||||
filippo.io/edwards25519 v1.1.0 // indirect | filippo.io/edwards25519 v1.1.0 // indirect | ||||
github.com/go-redis/redis v6.15.9+incompatible | |||||
github.com/goccy/go-json v0.10.2 // indirect | github.com/goccy/go-json v0.10.2 // indirect | ||||
github.com/golang/snappy v0.0.4 // indirect | github.com/golang/snappy v0.0.4 // indirect | ||||
github.com/gomodule/redigo v2.0.0+incompatible | |||||
github.com/json-iterator/go v1.1.12 // indirect | github.com/json-iterator/go v1.1.12 // indirect | ||||
github.com/mattn/go-isatty v0.0.19 // indirect | github.com/mattn/go-isatty v0.0.19 // indirect | ||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||||
@@ -7,22 +7,23 @@ import ( | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/utils/cache" | "code.fnuoos.com/EggPlanet/egg_models.git/utils/cache" | ||||
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" | zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" | ||||
"fmt" | "fmt" | ||||
"github.com/gomodule/redigo/redis" | |||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
func NewSysCfgDb(engine *xorm.Engine, redisAddr string) dao.SysCfgDao { | |||||
if redisAddr != "" { | |||||
cache.NewRedis(redisAddr) | |||||
func NewSysCfgDb(engine *xorm.Engine, conn redis.Conn) dao.SysCfgDao { | |||||
if conn != nil { | |||||
cache.NewRedisConn(conn) | |||||
} | } | ||||
return &SysCfgDb{ | return &SysCfgDb{ | ||||
Db: engine, | Db: engine, | ||||
RedisAddr: redisAddr, | |||||
RedisAddr: conn, | |||||
} | } | ||||
} | } | ||||
type SysCfgDb struct { | type SysCfgDb struct { | ||||
Db *xorm.Engine | Db *xorm.Engine | ||||
RedisAddr string | |||||
RedisAddr redis.Conn | |||||
} | } | ||||
func (s SysCfgDb) SysCfgGetAll() (*[]model.SysCfg, error) { | func (s SysCfgDb) SysCfgGetAll() (*[]model.SysCfg, error) { | ||||
@@ -34,6 +34,7 @@ type Config struct { | |||||
} | } | ||||
var pool *redigo.Pool | var pool *redigo.Pool | ||||
var redisConn redigo.Conn | |||||
var conf *Config | var conf *Config | ||||
func NewRedis(addr string) { | func NewRedis(addr string) { | ||||
@@ -75,9 +76,23 @@ func NewRedis(addr string) { | |||||
} | } | ||||
} | } | ||||
func NewRedisConn(conn redigo.Conn) { | |||||
redisConn = conn | |||||
} | |||||
// | |||||
//func Do(cmd string, args ...interface{}) (reply interface{}, err error) { | |||||
// conn := pool.Get() | |||||
// defer conn.Close() | |||||
// return conn.Do(cmd, args...) | |||||
//} | |||||
func Do(cmd string, args ...interface{}) (reply interface{}, err error) { | func Do(cmd string, args ...interface{}) (reply interface{}, err error) { | ||||
conn := pool.Get() | |||||
defer conn.Close() | |||||
var conn = redisConn | |||||
if redisConn == nil { | |||||
conn = pool.Get() | |||||
defer conn.Close() | |||||
} | |||||
return conn.Do(cmd, args...) | return conn.Do(cmd, args...) | ||||
} | } | ||||