database

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheAble

type CacheAble interface {
	CacheKey() string
}

type DB

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

DB is a logical database with multiple underlying physical databases forming a single master multiple slaves topology. Reads and writes are automatically directed to the correct physical db.

func NewMySQLDB

func NewMySQLDB(cfg config.MySQL, connCfg config.MySQLConnCfg) (*DB, error)

NewMySQLDB create the mysql master/slaves cluster

func (*DB) Master

func (db *DB) Master() *gorm.DB

Master returns the master physical database

func (*DB) Ping

func (db *DB) Ping() error

Ping verifies if a connection to each physical database is still alive, establishing a connection if necessary.

func (*DB) SetMaxIdleConns

func (db *DB) SetMaxIdleConns(n int)

SetMaxIdleConns sets the maximum number of connections in the idle connection pool for each underlying physical db. If MaxOpenConns is greater than 0 but less than the new MaxIdleConns then the new MaxIdleConns will be reduced to match the MaxOpenConns limit If n <= 0, no idle connections are retained.

func (*DB) SetMaxOpenConns

func (db *DB) SetMaxOpenConns(n int)

SetMaxOpenConns sets the maximum number of open connections to each physical database. If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than MaxIdleConns, then MaxIdleConns will be reduced to match the new MaxOpenConns limit. If n <= 0, then there is no limit on the number of open connections. The default is 0 (unlimited).

type RedisDB

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

func NewRedisDB

func NewRedisDB(cfg config.Redis) (*RedisDB, error)

NewRedisDB create the redis connection

func (*RedisDB) Del

func (r *RedisDB) Del(key string) *redis.IntCmd

func (*RedisDB) Ping

func (r *RedisDB) Ping() error

func (*RedisDB) SetNX

func (r *RedisDB) SetNX(key string, value interface{}, expiration time.Duration) bool

func (*RedisDB) SetWithLongTerm

func (r *RedisDB) SetWithLongTerm(obj CacheAble) error

func (*RedisDB) SetWithShortTerm

func (r *RedisDB) SetWithShortTerm(obj CacheAble) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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