Documentation ¶
Index ¶
- Constants
- Variables
- func GenRowObjRegisterFileByCfg(cfg *Config, regFilePath string, regPackName string)
- type CacheConf
- type CacheDriver
- func (d *CacheDriver) BLPop(timeout time.Duration, keys ...string) ([]string, error)
- func (d *CacheDriver) Close() error
- func (d *CacheDriver) Del(keys ...string) (int64, error)
- func (d *CacheDriver) Exists(keys ...string) (int64, error)
- func (d *CacheDriver) Expire(key string, expiration time.Duration) (bool, error)
- func (d *CacheDriver) ExpireAt(key string, tm time.Time) (bool, error)
- func (d *CacheDriver) Get(key string) (string, error)
- func (d *CacheDriver) HDel(key string, field string) (int64, error)
- func (d *CacheDriver) HExists(key string, field string) (bool, error)
- func (d *CacheDriver) HGetAll(key string) (map[string]string, error)
- func (d *CacheDriver) HMGet(key string, fields ...string) ([]interface{}, error)
- func (d *CacheDriver) HMSet(key string, fields map[string]interface{}) error
- func (d *CacheDriver) HSet(key string, field string, value interface{}) (bool, error)
- func (d *CacheDriver) HSetNX(key string, field string, value interface{}) (bool, error)
- func (d *CacheDriver) Incr(key string) (int64, error)
- func (d *CacheDriver) Keys(pattern string) ([]string, error)
- func (d *CacheDriver) LLen(key string) (int64, error)
- func (d *CacheDriver) LRange(key string, start int64, stop int64) ([]string, error)
- func (d *CacheDriver) LRem(key string, count int64, value interface{}) (int64, error)
- func (d *CacheDriver) LSet(key string, index int64, value interface{}) error
- func (d *CacheDriver) MGet(keys ...string) ([]interface{}, error)
- func (d *CacheDriver) MSet(pairs ...interface{}) (string, error)
- func (d *CacheDriver) Open(addr string, pwd string, db int) error
- func (d *CacheDriver) Persist(key string) (bool, error)
- func (d *CacheDriver) Publish(channel string, message interface{}) error
- func (d *CacheDriver) RPush(key string, values ...interface{}) error
- func (d *CacheDriver) Set(key string, value interface{}, expiration time.Duration) error
- func (d *CacheDriver) SetNX(key string, value interface{}, expiration time.Duration) (bool, error)
- func (d *CacheDriver) Subscribe(cb RedisSubscribeCb, channels ...string) error
- func (d *CacheDriver) TTL(key string) (time.Duration, error)
- func (d *CacheDriver) WaitExit()
- type Cacheable
- type Config
- type DBConf
- type DBTableRow
- type DataCenter
- func (c *DataCenter) AddCacheDriver(tag string, driver *CacheDriver)
- func (c *DataCenter) AddDbDriver(tag string, driver *DbDriver)
- func (c *DataCenter) AddWorker(tag string, w *DataWorker)
- func (c *DataCenter) CloseAllCacheDriver()
- func (c *DataCenter) CloseAllDbDriver()
- func (c *DataCenter) GetCacheDriver(tag string) (*CacheDriver, bool)
- func (c *DataCenter) GetDbDriver(tag string) (*DbDriver, bool)
- func (c *DataCenter) GetWorker(tag string) (*DataWorker, bool)
- func (c *DataCenter) Start(saveIntv time.Duration, clearExpireIntv time.Duration)
- func (c *DataCenter) Stop()
- type DataWorker
- func (w *DataWorker) ClearExpireCaches() error
- func (w *DataWorker) GetAllCacheKeys() ([]string, error)
- func (w *DataWorker) GetCacheData(obj Cacheable, key string, fields ...string) error
- func (w *DataWorker) GetCacheDataToMap(key string, fields ...string) (map[string]string, error)
- func (w *DataWorker) HasCache() bool
- func (w *DataWorker) HasDb() bool
- func (w *DataWorker) Init(reflectName string, insertTag string, selectTag string, selectKeyTag string, ...) error
- func (w *DataWorker) InsertToDb(mapper interface{}) (int64, error)
- func (w *DataWorker) LoadFromCache(obj Cacheable, key string) error
- func (w *DataWorker) PreloadData(obj Cacheable, mapper interface{}) error
- func (w *DataWorker) SaveCaches() error
- func (w *DataWorker) SelectFromDb(mapper interface{}) (DBTableRow, error)
- func (w *DataWorker) SelectRowsFromDb(mapper interface{}, limitCnt int) ([]DBTableRow, error)
- func (w *DataWorker) SetCacheData(obj Cacheable, key string, fields ...string) error
- func (w *DataWorker) SetCacheDataByMap(key string, mapField2Val map[string]interface{}) error
- func (w *DataWorker) SetCacheExpire(key string, expiration time.Duration) error
- func (w *DataWorker) SetCacheUpdated(key string)
- func (w *DataWorker) Start(saveIntv time.Duration, clearExpireIntv time.Duration)
- func (w *DataWorker) Stop()
- func (w *DataWorker) UpdateToDb(mapper interface{}) error
- type DbDriver
- func (d *DbDriver) Close() error
- func (d *DbDriver) CreateTableRow(rowReflectName string) (DBTableRow, error)
- func (d *DbDriver) Exec(query string, args ...interface{}) (sql.Result, error)
- func (d *DbDriver) NameExec(query string, mapper interface{}) error
- func (d *DbDriver) NameInsert(query string, mapper interface{}) (int64, error)
- func (d *DbDriver) NameQuery(rowReflectName string, query string, mapper interface{}) ([]DBTableRow, error)
- func (d *DbDriver) Open(userName string, pwd string, host string, port uint16, database string, ...) error
- func (d *DbDriver) ReuseTableRow(rowObj DBTableRow, rowReflectName string)
- func (d *DbDriver) Select(dest interface{}, query string, args ...interface{}) error
- type RedisSubscribeCb
- type StorageConf
- type WorkerConf
Constants ¶
View Source
const ( INIT_REUSE_COUNT = 10 MAX_REUSE_COUNT = 100 )
View Source
const (
CACHE_FIELD_UPDATE_TIME = "cache_update_time"
)
Variables ¶
View Source
var ( ErrNoCache = errors.New("no cache") ErrNoDb = errors.New("no db") ErrWorkerObjectIsNil = errors.New("object is nil") ErrWorkerRowObjIsNil = errors.New("row object is nil") ErrWorkerInsertFieldNotFind = errors.New("insert field not find") ErrWorkerKeyFieldNotDefine = errors.New("key field not define") ErrWorkerCacheNotExist = errors.New("cache data no exist") ErrWorkerDBNotExist = errors.New("db data no data") ErrWorkerFieldNotExist = errors.New("some field not exist") ErrWorkerCacheKeyNotFind = errors.New("cache key not define") ErrWorkerCacheKeyNotString = errors.New("cache key not string") )
View Source
var ( ErrMapperIsNil = errors.New("mapper is nil") ErrNotRowObject = errors.New("not table row object") )
View Source
var Builder = &builder{ logger: yx.NewLogger("gamedb.Builder"), }
View Source
var (
ErrCacheSubscribeFailed = errors.New("Subscribe failed")
)
View Source
var RowObjFactory = yx.NewObjectFactory()
Functions ¶
Types ¶
type CacheDriver ¶
type CacheDriver struct {
// contains filtered or unexported fields
}
func NewCacheDriver ¶
func NewCacheDriver() *CacheDriver
func (*CacheDriver) Close ¶
func (d *CacheDriver) Close() error
func (*CacheDriver) HMGet ¶
func (d *CacheDriver) HMGet(key string, fields ...string) ([]interface{}, error)
func (*CacheDriver) HMSet ¶
func (d *CacheDriver) HMSet(key string, fields map[string]interface{}) error
func (*CacheDriver) HSet ¶
func (d *CacheDriver) HSet(key string, field string, value interface{}) (bool, error)
hash
func (*CacheDriver) HSetNX ¶
func (d *CacheDriver) HSetNX(key string, field string, value interface{}) (bool, error)
func (*CacheDriver) LRem ¶
func (d *CacheDriver) LRem(key string, count int64, value interface{}) (int64, error)
func (*CacheDriver) LSet ¶
func (d *CacheDriver) LSet(key string, index int64, value interface{}) error
func (*CacheDriver) MGet ¶
func (d *CacheDriver) MGet(keys ...string) ([]interface{}, error)
func (*CacheDriver) MSet ¶
func (d *CacheDriver) MSet(pairs ...interface{}) (string, error)
func (*CacheDriver) Publish ¶
func (d *CacheDriver) Publish(channel string, message interface{}) error
func (*CacheDriver) RPush ¶
func (d *CacheDriver) RPush(key string, values ...interface{}) error
list
func (*CacheDriver) Set ¶
func (d *CacheDriver) Set(key string, value interface{}, expiration time.Duration) error
func (*CacheDriver) Subscribe ¶
func (d *CacheDriver) Subscribe(cb RedisSubscribeCb, channels ...string) error
func (*CacheDriver) WaitExit ¶
func (d *CacheDriver) WaitExit()
type Config ¶
type Config struct { SaveIntv int `json:"save_interval"` ClearIntv int `json:"clear_interval"` Storages []*StorageConf `json:"storages"` }
type DBTableRow ¶
type DBTableRow interface { Cacheable }
type DataCenter ¶
type DataCenter struct {
// contains filtered or unexported fields
}
func NewDataCenter ¶
func NewDataCenter() *DataCenter
func (*DataCenter) AddCacheDriver ¶
func (c *DataCenter) AddCacheDriver(tag string, driver *CacheDriver)
func (*DataCenter) AddDbDriver ¶
func (c *DataCenter) AddDbDriver(tag string, driver *DbDriver)
func (*DataCenter) AddWorker ¶
func (c *DataCenter) AddWorker(tag string, w *DataWorker)
func (*DataCenter) CloseAllCacheDriver ¶
func (c *DataCenter) CloseAllCacheDriver()
func (*DataCenter) CloseAllDbDriver ¶
func (c *DataCenter) CloseAllDbDriver()
func (*DataCenter) GetCacheDriver ¶
func (c *DataCenter) GetCacheDriver(tag string) (*CacheDriver, bool)
func (*DataCenter) GetDbDriver ¶
func (c *DataCenter) GetDbDriver(tag string) (*DbDriver, bool)
func (*DataCenter) GetWorker ¶
func (c *DataCenter) GetWorker(tag string) (*DataWorker, bool)
func (*DataCenter) Start ¶
func (c *DataCenter) Start(saveIntv time.Duration, clearExpireIntv time.Duration)
func (*DataCenter) Stop ¶
func (c *DataCenter) Stop()
type DataWorker ¶
type DataWorker struct {
// contains filtered or unexported fields
}
func NewDataWorker ¶
func NewDataWorker(cacheDriver *CacheDriver, cacheKeyName string, mapCacheField2DbField map[string]string, dbDriver *DbDriver, tableName string) *DataWorker
func (*DataWorker) ClearExpireCaches ¶
func (w *DataWorker) ClearExpireCaches() error
func (*DataWorker) GetAllCacheKeys ¶
func (w *DataWorker) GetAllCacheKeys() ([]string, error)
func (*DataWorker) GetCacheData ¶
func (w *DataWorker) GetCacheData(obj Cacheable, key string, fields ...string) error
func (*DataWorker) GetCacheDataToMap ¶
func (*DataWorker) HasCache ¶ added in v0.1.4
func (w *DataWorker) HasCache() bool
func (*DataWorker) HasDb ¶ added in v0.1.4
func (w *DataWorker) HasDb() bool
func (*DataWorker) InsertToDb ¶
func (w *DataWorker) InsertToDb(mapper interface{}) (int64, error)
func (*DataWorker) LoadFromCache ¶
func (w *DataWorker) LoadFromCache(obj Cacheable, key string) error
func (*DataWorker) PreloadData ¶
func (w *DataWorker) PreloadData(obj Cacheable, mapper interface{}) error
func (*DataWorker) SaveCaches ¶
func (w *DataWorker) SaveCaches() error
func (*DataWorker) SelectFromDb ¶
func (w *DataWorker) SelectFromDb(mapper interface{}) (DBTableRow, error)
func (*DataWorker) SelectRowsFromDb ¶ added in v0.1.4
func (w *DataWorker) SelectRowsFromDb(mapper interface{}, limitCnt int) ([]DBTableRow, error)
func (*DataWorker) SetCacheData ¶
func (w *DataWorker) SetCacheData(obj Cacheable, key string, fields ...string) error
func (*DataWorker) SetCacheDataByMap ¶
func (w *DataWorker) SetCacheDataByMap(key string, mapField2Val map[string]interface{}) error
func (*DataWorker) SetCacheExpire ¶
func (w *DataWorker) SetCacheExpire(key string, expiration time.Duration) error
func (*DataWorker) SetCacheUpdated ¶
func (w *DataWorker) SetCacheUpdated(key string)
func (*DataWorker) Start ¶
func (w *DataWorker) Start(saveIntv time.Duration, clearExpireIntv time.Duration)
func (*DataWorker) Stop ¶
func (w *DataWorker) Stop()
func (*DataWorker) UpdateToDb ¶
func (w *DataWorker) UpdateToDb(mapper interface{}) error
type DbDriver ¶
type DbDriver struct {
// contains filtered or unexported fields
}
func NewDbDriver ¶
func NewDbDriver(rowObjFactory *yx.ObjectFactory) *DbDriver
func (*DbDriver) CreateTableRow ¶
func (d *DbDriver) CreateTableRow(rowReflectName string) (DBTableRow, error)
func (*DbDriver) NameInsert ¶
func (*DbDriver) NameQuery ¶
func (d *DbDriver) NameQuery(rowReflectName string, query string, mapper interface{}) ([]DBTableRow, error)
func (*DbDriver) ReuseTableRow ¶
func (d *DbDriver) ReuseTableRow(rowObj DBTableRow, rowReflectName string)
type RedisSubscribeCb ¶
type StorageConf ¶
type StorageConf struct { Cache *CacheConf `json:"cache"` Db *DBConf `json:"db"` Workers []*WorkerConf `json:"workers"` }
type WorkerConf ¶
type WorkerConf struct { Tag string `json:"tag"` CacheKey string `json:"cache_key"` MapCacheField2DbField map[string]string `json:"field_map"` TableName string `json:"table_name"` RowObj string `json:"row_obj"` InsertTag string `json:"insert_tag"` SelectTag string `json:"select_tag"` SelectKeyTag string `json:"select_key_tag"` UpdateTag string `json:"update_tag"` UpdateKeyTag string `json:"update_key_tag"` }
Click to show internal directories.
Click to hide internal directories.