Browse Source

update

tags/v0.0.2
dengbiao 2 weeks ago
parent
commit
1dbfb60c1b
3 changed files with 25 additions and 7 deletions
  1. +2
    -0
      go.mod
  2. +6
    -5
      src/implement/sys_cfg_implement.go
  3. +17
    -2
      utils/cache/redis.go

+ 2
- 0
go.mod View File

@@ -12,8 +12,10 @@ require (

require (
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/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/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect


+ 6
- 5
src/implement/sys_cfg_implement.go View File

@@ -7,22 +7,23 @@ import (
"code.fnuoos.com/EggPlanet/egg_models.git/utils/cache"
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx"
"fmt"
"github.com/gomodule/redigo/redis"
"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{
Db: engine,
RedisAddr: redisAddr,
RedisAddr: conn,
}
}

type SysCfgDb struct {
Db *xorm.Engine
RedisAddr string
RedisAddr redis.Conn
}

func (s SysCfgDb) SysCfgGetAll() (*[]model.SysCfg, error) {


+ 17
- 2
utils/cache/redis.go View File

@@ -34,6 +34,7 @@ type Config struct {
}

var pool *redigo.Pool
var redisConn redigo.Conn
var conf *Config

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) {
conn := pool.Get()
defer conn.Close()
var conn = redisConn
if redisConn == nil {
conn = pool.Get()
defer conn.Close()
}
return conn.Do(cmd, args...)
}



Loading…
Cancel
Save