暂存pull dev
This commit is contained in:
parent
b9d51378f3
commit
924da6fdd8
@ -2,33 +2,61 @@ package modules
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/lego/sys/redis"
|
||||||
"go_dreamfactory/sys/cache"
|
"go_dreamfactory/sys/cache"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DBModel struct {
|
type DBModel struct {
|
||||||
model proto.Message
|
*MComp_DBComp
|
||||||
|
pbData proto.Message
|
||||||
|
prefix string //rediskey前缀
|
||||||
|
tableName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DBModel) Model(model proto.Message) *DBModel {
|
func NewDBModel(c *MComp_DBComp) *DBModel {
|
||||||
m.model = model
|
return &DBModel{MComp_DBComp: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DBModel) SetData(model proto.Message) *DBModel {
|
||||||
|
m.pbData = model
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *DBModel) GetData() proto.Message {
|
||||||
|
return m.pbData
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DBModel) SetPrefix(prefix string) {
|
||||||
|
m.prefix = prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DBModel) SetTableName(tableName string) {
|
||||||
|
m.tableName = tableName
|
||||||
|
}
|
||||||
|
|
||||||
func (m *DBModel) OnChange() {
|
func (m *DBModel) OnChange() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DBModel) Set() {
|
func (m *DBModel) Set(key string, val interface{}) {
|
||||||
|
|
||||||
|
//调用写入mongo日志接口
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取数据
|
//获取数据
|
||||||
func (m *DBModel) Get(key string) {
|
func (m *DBModel) Get(uid string) {
|
||||||
err := cache.GetRds().Get(key, m.model)
|
if m.prefix == "" {
|
||||||
|
log.Errorf("get data err,because prefix not setting")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := cache.Redis().Get(fmt.Sprintf("%s:%s", m.prefix, uid), m.pbData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("err:%v", err)
|
if err.Error() != redis.RedisNil.Error() {
|
||||||
|
log.Errorf("err:%v", err)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ func (this *Model_Comp) Init(service core.IService, module core.IModule, comp co
|
|||||||
this.ModuleCompBase.Init(service, module, comp, options)
|
this.ModuleCompBase.Init(service, module, comp, options)
|
||||||
this.Redis = cache.Redis()
|
this.Redis = cache.Redis()
|
||||||
this.DB = db.Mgo()
|
this.DB = db.Mgo()
|
||||||
|
NewDBModel(this)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (this *Model_Comp) Start() (err error) {
|
func (this *Model_Comp) Start() (err error) {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package modules
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go_dreamfactory/pb"
|
|
||||||
"go_dreamfactory/sys/cache"
|
"go_dreamfactory/sys/cache"
|
||||||
"go_dreamfactory/sys/db"
|
"go_dreamfactory/sys/db"
|
||||||
"os"
|
"os"
|
||||||
@ -23,10 +22,13 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInitData(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
dbmodel := new(DBModel)
|
// userModel := NewUserModel()
|
||||||
model := &pb.Cache_UserData{}
|
// userModel.Set("1_62a729fc0e01ab2819553242",)
|
||||||
dbmodel.Model(model)
|
// fmt.Printf("%v", userModel.GetData().(*pb.Cache_UserData))
|
||||||
dbmodel.Get("user:62a2bd064098aa8ff982f2e2")
|
}
|
||||||
fmt.Printf("%v", model.SessionId)
|
|
||||||
|
func TestSet(t *testing.T) {
|
||||||
|
// um := NewUserModel("1_62a729fc0e01ab2819553242")
|
||||||
|
|
||||||
}
|
}
|
@ -1,8 +0,0 @@
|
|||||||
package user
|
|
||||||
|
|
||||||
import "go_dreamfactory/pb"
|
|
||||||
|
|
||||||
type UserModel struct {
|
|
||||||
pb.DB_UserData
|
|
||||||
}
|
|
||||||
|
|
19
modules/user/user_model.go
Normal file
19
modules/user/user_model.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/modules"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserModel struct {
|
||||||
|
modules.DBModel
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUserModel() *UserModel {
|
||||||
|
model := new(UserModel)
|
||||||
|
model.SetPrefix("user") //每个Model有自己的唯一key
|
||||||
|
model.SetTableName("user")
|
||||||
|
model.SetData(&pb.Cache_UserData{}) //设置具体数据类型
|
||||||
|
// model.Get(uid) //获取model数据
|
||||||
|
return model
|
||||||
|
}
|
6
sys/cache/cache.go
vendored
6
sys/cache/cache.go
vendored
@ -17,15 +17,12 @@ type Cache struct {
|
|||||||
redis redis.ISys
|
redis redis.ISys
|
||||||
}
|
}
|
||||||
|
|
||||||
var rdsIns redis.ISys
|
|
||||||
|
|
||||||
//初始化 redis 对象
|
//初始化 redis 对象
|
||||||
func (this *Cache) init() (err error) {
|
func (this *Cache) init() (err error) {
|
||||||
this.redis, err = redis.NewSys(
|
this.redis, err = redis.NewSys(
|
||||||
redis.SetRedisType(redis.Redis_Cluster),
|
redis.SetRedisType(redis.Redis_Cluster),
|
||||||
redis.SetRedis_Cluster_Addr(this.options.Redis_Addr),
|
redis.SetRedis_Cluster_Addr(this.options.Redis_Addr),
|
||||||
redis.SetRedis_Cluster_Password(this.options.Redis_Password))
|
redis.SetRedis_Cluster_Password(this.options.Redis_Password))
|
||||||
rdsIns = this.redis
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +30,3 @@ func (this *Cache) init() (err error) {
|
|||||||
func (this *Cache) Redis() redis.ISys {
|
func (this *Cache) Redis() redis.ISys {
|
||||||
return this.redis
|
return this.redis
|
||||||
}
|
}
|
||||||
func GetRds() redis.ISys {
|
|
||||||
return rdsIns
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user