diff --git a/sys/cache/cache.go b/sys/cache/cache.go index 8fa30047e..28aa5adef 100644 --- a/sys/cache/cache.go +++ b/sys/cache/cache.go @@ -2,6 +2,10 @@ package cache import "go_dreamfactory/lego/sys/redis" +/* +缓存系统的基础结构 包含系统的配置阐述以及 底层操作redis的 redis.ISys 对象 +*/ + func newSys(options Options) (sys *Cache, err error) { sys = &Cache{options: options} err = sys.init() @@ -13,6 +17,7 @@ type Cache struct { redis redis.ISys } +//初始化 redis 对象 func (this *Cache) init() (err error) { this.redis, err = redis.NewSys( redis.SetRedisType(redis.Redis_Cluster), diff --git a/sys/cache/core.go b/sys/cache/core.go index ddda681f7..c09e98254 100644 --- a/sys/cache/core.go +++ b/sys/cache/core.go @@ -1,17 +1,23 @@ package cache +/* +redis 缓存数据管理系统 +*/ + type ( ISys interface { - IUser - IPack - IMail + IUser //户模块的相关缓存接口 + IPack //背包模块的线管缓存接口 + IMail //邮件相关的缓存接口 } ) const () +//全局使用的系统对象 var Defsys ISys +//初始化缓存系统 func OnInit(config map[string]interface{}, option ...Option) (err error) { var options Options if options, err = newOptions(config, option...); err != nil { @@ -21,6 +27,7 @@ func OnInit(config map[string]interface{}, option ...Option) (err error) { return } +//系统实例化接口 每个系统默认都会提供全局以及实例化的接口 func NewSys(option ...Option) (sys ISys, err error) { var options Options if options, err = newOptionsByOption(option...); err != nil { diff --git a/sys/cache/options.go b/sys/cache/options.go index e42f945e2..aa940d657 100644 --- a/sys/cache/options.go +++ b/sys/cache/options.go @@ -6,23 +6,30 @@ import ( "go_dreamfactory/lego/utils/mapstructure" ) +/* + 系统启动相关的配置参数定义 +*/ type Option func(*Options) type Options struct { - Redis_Addr []string - Redis_Password string + Redis_Addr []string //redis 的集群地址 + Redis_Password string //redis的密码 } +//设置系统的集群地址 func Set_Redis_Addr(v []string) Option { return func(o *Options) { o.Redis_Addr = v } } +//设置系统的密码配置 func Set_Redis_Password(v string) Option { return func(o *Options) { o.Redis_Password = v } } + +//更具 map对象或者Option 序列化 系统参数对象 func newOptions(config map[string]interface{}, opts ...Option) (Options, error) { options := Options{} if config != nil { @@ -37,6 +44,7 @@ func newOptions(config map[string]interface{}, opts ...Option) (Options, error) return options, nil } +//更具 Option 序列化 系统参数对象 func newOptionsByOption(opts ...Option) (Options, error) { options := Options{} for _, o := range opts {