gamedb

package module
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2022 License: BSD-2-Clause Imports: 12 Imported by: 0

README

gamedb

Documentation

Index

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

func GenRowObjRegisterFileByCfg

func GenRowObjRegisterFileByCfg(cfg *Config, regFilePath string, regPackName string)

Types

type CacheConf

type CacheConf struct {
	Tag  string `json:"tag"`
	Addr string `json:"addr"`
	Pwd  string `json:"pwd"`
	Db   int    `json:"db"`
}

type CacheDriver

type CacheDriver struct {
	// contains filtered or unexported fields
}

func NewCacheDriver

func NewCacheDriver() *CacheDriver

func (*CacheDriver) BLPop

func (d *CacheDriver) BLPop(timeout time.Duration, keys ...string) ([]string, error)

func (*CacheDriver) Close

func (d *CacheDriver) Close() error

func (*CacheDriver) Del

func (d *CacheDriver) Del(keys ...string) (int64, error)

func (*CacheDriver) Exists

func (d *CacheDriver) Exists(keys ...string) (int64, error)

func (*CacheDriver) Expire

func (d *CacheDriver) Expire(key string, expiration time.Duration) (bool, error)

func (*CacheDriver) ExpireAt

func (d *CacheDriver) ExpireAt(key string, tm time.Time) (bool, error)

func (*CacheDriver) Get

func (d *CacheDriver) Get(key string) (string, error)

func (*CacheDriver) HDel

func (d *CacheDriver) HDel(key string, field string) (int64, error)

func (*CacheDriver) HExists

func (d *CacheDriver) HExists(key string, field string) (bool, error)

func (*CacheDriver) HGetAll

func (d *CacheDriver) HGetAll(key string) (map[string]string, 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) Incr

func (d *CacheDriver) Incr(key string) (int64, error)

func (*CacheDriver) Keys

func (d *CacheDriver) Keys(pattern string) ([]string, error)

func (*CacheDriver) LLen

func (d *CacheDriver) LLen(key string) (int64, error)

func (*CacheDriver) LRange

func (d *CacheDriver) LRange(key string, start int64, stop int64) ([]string, 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) Open

func (d *CacheDriver) Open(addr string, pwd string, db int) error

func (*CacheDriver) Persist

func (d *CacheDriver) Persist(key string) (bool, 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) SetNX

func (d *CacheDriver) SetNX(key string, value interface{}, expiration time.Duration) (bool, error)

func (*CacheDriver) Subscribe

func (d *CacheDriver) Subscribe(cb RedisSubscribeCb, channels ...string) error

func (*CacheDriver) TTL

func (d *CacheDriver) TTL(key string) (time.Duration, error)

func (*CacheDriver) WaitExit

func (d *CacheDriver) WaitExit()

type Cacheable

type Cacheable interface {
	FromCache(mapField2Val map[string]string) error
	ToCache(fields []string) (map[string]interface{}, error)
}

type Config

type Config struct {
	SaveIntv  int            `json:"save_interval"`
	ClearIntv int            `json:"clear_interval"`
	Storages  []*StorageConf `json:"storages"`
}

type DBConf

type DBConf struct {
	Tag     string `json:"tag"`
	Addr    string `json:"addr"`
	Port    uint16 `json:"port"`
	DbName  string `json:"name"`
	Acc     string `json:"acc"`
	Pwd     string `json:"pwd"`
	Charset string `json:"charset"`
}

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 (w *DataWorker) GetCacheDataToMap(key string, fields ...string) (map[string]string, error)

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) Init

func (w *DataWorker) Init(reflectName string, insertTag string, selectTag string, selectKeyTag string, updateTag string, updateKeyTag string) error

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) Close

func (d *DbDriver) Close() error

func (*DbDriver) CreateTableRow

func (d *DbDriver) CreateTableRow(rowReflectName string) (DBTableRow, error)

func (*DbDriver) Exec

func (d *DbDriver) Exec(query string, args ...interface{}) (sql.Result, error)

func (*DbDriver) NameExec

func (d *DbDriver) NameExec(query string, mapper interface{}) error

func (*DbDriver) NameInsert

func (d *DbDriver) NameInsert(query string, mapper interface{}) (int64, error)

func (*DbDriver) NameQuery

func (d *DbDriver) NameQuery(rowReflectName string, query string, mapper interface{}) ([]DBTableRow, error)

func (*DbDriver) Open

func (d *DbDriver) Open(userName string, pwd string, host string, port uint16, database string, charset string) error

func (*DbDriver) ReuseTableRow

func (d *DbDriver) ReuseTableRow(rowObj DBTableRow, rowReflectName string)

func (*DbDriver) Select

func (d *DbDriver) Select(dest interface{}, query string, args ...interface{}) error

type RedisSubscribeCb

type RedisSubscribeCb func(channel string, pattern string, payload string)

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"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL