diff --git a/modules/cache_com.go b/modules/cache_comp.go similarity index 92% rename from modules/cache_com.go rename to modules/cache_comp.go index 500a399dd..1f6b665aa 100644 --- a/modules/cache_com.go +++ b/modules/cache_comp.go @@ -5,6 +5,7 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/redis" + "go_dreamfactory/sys/cache" ) /* @@ -22,5 +23,6 @@ func (this *MComp_CacheComp) Init(service core.IService, module core.IModule, co this.ModuleCompBase.Init(service, module, comp, options) this.S = service.(base.IRPCXService) this.M = module + this.Redis = cache.Redis() return } diff --git a/modules/db_comp.go b/modules/db_comp.go index df3b7627a..e04f1fbe2 100644 --- a/modules/db_comp.go +++ b/modules/db_comp.go @@ -5,6 +5,7 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/mgo" + "go_dreamfactory/sys/db" ) /* @@ -22,5 +23,6 @@ func (this *MComp_DBComp) Init(service core.IService, module core.IModule, comp this.ModuleCompBase.Init(service, module, comp, options) this.S = service.(base.IRPCXService) this.M = module + this.DB = db.Mgo() return } diff --git a/sys/cache/cache.go b/sys/cache/cache.go index 28aa5adef..cb284640a 100644 --- a/sys/cache/cache.go +++ b/sys/cache/cache.go @@ -25,3 +25,8 @@ func (this *Cache) init() (err error) { redis.SetRedis_Cluster_Password(this.options.Redis_Password)) return } + +//初始化 redis 对象 +func (this *Cache) Redis() redis.ISys { + return this.redis +} diff --git a/sys/cache/core.go b/sys/cache/core.go index 4912a06de..d372608c3 100644 --- a/sys/cache/core.go +++ b/sys/cache/core.go @@ -1,11 +1,14 @@ package cache +import "go_dreamfactory/lego/sys/redis" + /* redis 缓存数据管理系统 */ type ( ISys interface { + Redis() redis.ISys IUser //户模块的相关缓存接口 IFriend //好友相关的缓存接口 } @@ -35,3 +38,8 @@ func NewSys(option ...Option) (sys ISys, err error) { Defsys, err = newSys(options) return } + +//系统实例化接口 每个系统默认都会提供全局以及实例化的接口 +func Redis() redis.ISys { + return Defsys.Redis() +} diff --git a/sys/db/core.go b/sys/db/core.go index 967c1431a..5937bc925 100644 --- a/sys/db/core.go +++ b/sys/db/core.go @@ -1,7 +1,10 @@ package db +import "go_dreamfactory/lego/sys/mgo" + type ( ISys interface { + Mgo() mgo.ISys IUser IMail IFriend @@ -27,3 +30,7 @@ func NewSys(option ...Option) (sys ISys, err error) { Defsys, err = newSys(options) return } + +func Mgo() mgo.ISys { + return Defsys.Mgo() +} diff --git a/sys/db/db.go b/sys/db/db.go index 832f8b9ad..e6e6086cd 100644 --- a/sys/db/db.go +++ b/sys/db/db.go @@ -24,3 +24,6 @@ func (this *DB) init() (err error) { } return } +func (this *DB) Mgo() mgo.ISys { + return this.mgo +}