db

package
v0.0.0-...-2f8f7b3 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_OPEN_CONNS = 256
	MAX_CONN_TIME  = 24 * 3600
	MAX_IDLE_CONNS = 32
	MAX_IDLE_TIME  = 5 * 60
)
View Source
const (
	REDIS_MAX_IDLE         = 30
	REDIS_MAX_ACTIVE       = 100
	REDIS_MAX_DILE_TIMEOUT = 180 * time.Second
)
View Source
const (
	REDIS_SCRIPT_GET     = "redis_get"
	REDIS_SCRIPT_HGET    = "redis_hget"
	REDIS_SCRIPT_SET     = "redis_set"
	REDIS_SCRIPT_HSET    = "redis_hset"
	REDIS_SCRIPT_UNLOCK  = "redis_unlock"
	REDIS_SCRIPT_HUNLOCK = "redis_hunlock"
	REDIS_SCRIPT_DEL     = "redis_del"
	REDIS_SCRIPT_HDEL    = "redis_hdel"
	REDIS_SCRIPT_PUSH    = "redis_push"
	REDIS_SCRIPT_POP     = "redis_pop"
	REDIS_SCRIPT_INCRBY  = "redis_incrby"
	REDIS_SCRIPT_GLOCK   = "redis_glock"
	REDIS_SCRIPT_GUNLOCK = "redis_gunlock"
)
View Source
const (
	GLOCK_TIMEOUT = 5
)

Variables

This section is empty.

Functions

func DebugDB

func DebugDB()

func SetRedisScript

func SetRedisScript()

func StartMysql

func StartMysql(cfg MysqlConf) error

func StartRedis

func StartRedis(cfg RedisConf)

func StopMysql

func StopMysql()

func StopRedis

func StopRedis()

Types

type GLocker

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

func NewGLocker

func NewGLocker(key string) *GLocker

func (*GLocker) Lock

func (g *GLocker) Lock() bool

func (*GLocker) Release

func (g *GLocker) Release()

func (*GLocker) UnLock

func (g *GLocker) UnLock()

type IGLocker

type IGLocker interface {
	Lock() bool
	UnLock()
	Release()
}

type IMysql

type IMysql interface {
	Connect(user, password, ip string, port int, db string) error
	IsConnected() bool
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Close()
}

type IRedis

type IRedis interface {
	InitConnect(ip string, port int, password string, db int)
	SetScript(key string, script string, keyCount int)
	DoScript(key string, args ...interface{}) (reply interface{}, err error)
	GetIdleCount() int
	GetActiveCount() int
	DoCmd(cmd string, args ...interface{}) (reply interface{}, err error)
	Close()
}

type Mysql

type Mysql struct {
	// contains filtered or unexported fields
}
var MysqlHelper *Mysql

func NewMysql

func NewMysql() *Mysql

func (*Mysql) Close

func (m *Mysql) Close()

func (*Mysql) Connect

func (m *Mysql) Connect(user, password, ip string, port int, db string) error

func (*Mysql) Exec

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

insert/update/delete

func (*Mysql) IsConnected

func (m *Mysql) IsConnected() bool

func (*Mysql) Query

func (m *Mysql) Query(query string, args ...interface{}) (*sql.Rows, error)

lines query

func (*Mysql) QueryRow

func (m *Mysql) QueryRow(query string, args ...interface{}) *sql.Row

line query

func (*Mysql) Stats

func (m *Mysql) Stats() *sql.DBStats

type Redis

type Redis struct {
	// contains filtered or unexported fields
}
var RedisHelper *Redis

func NewRedis

func NewRedis() *Redis

func (*Redis) Close

func (r *Redis) Close()

func (*Redis) Decrby

func (r *Redis) Decrby(key string, dec int) error

func (*Redis) DelKey

func (r *Redis) DelKey(key string) error

region key

func (*Redis) DoCmd

func (r *Redis) DoCmd(cmd string, args ...interface{}) (reply interface{}, err error)

func (*Redis) DoScript

func (r *Redis) DoScript(key string, args ...interface{}) (reply interface{}, err error)

func (*Redis) GetActiveCount

func (r *Redis) GetActiveCount() int

func (*Redis) GetIdleCount

func (r *Redis) GetIdleCount() int

func (*Redis) GetString

func (r *Redis) GetString(key string) (string, error)

func (*Redis) HExists

func (r *Redis) HExists(key string, field interface{}) (bool, error)

func (*Redis) HGet

func (r *Redis) HGet(key string, field interface{}) (string, error)

func (*Redis) HGetAll

func (r *Redis) HGetAll(key string) (map[string]string, error)

func (*Redis) HKeys

func (r *Redis) HKeys(key string) ([]string, error)

func (*Redis) HLen

func (r *Redis) HLen(key string) (int64, error)

func (*Redis) HMget

func (r *Redis) HMget(key string, fields ...interface{}) ([]string, error)

func (*Redis) HMset

func (r *Redis) HMset(key string, fields ...interface{}) error

func (*Redis) HSet

func (r *Redis) HSet(key string, field interface{}, value interface{}) error

func (*Redis) Hdel

func (r *Redis) Hdel(key string, fields ...interface{}) error

region hash

func (*Redis) Incrby

func (r *Redis) Incrby(key string, inc int) error

func (*Redis) InitConnect

func (r *Redis) InitConnect(ip string, port int, password string, db int)

func (*Redis) LIndex

func (r *Redis) LIndex(key string, index int) (string, error)

region list

func (*Redis) LLen

func (r *Redis) LLen(key string) (int64, error)

func (*Redis) LPop

func (r *Redis) LPop(key string) (string, error)

func (*Redis) LPush

func (r *Redis) LPush(key string, values ...interface{}) error

func (*Redis) LRange

func (r *Redis) LRange(key string, start, end int) ([]string, error)

func (*Redis) RPop

func (r *Redis) RPop(key string) (string, error)

func (*Redis) RPush

func (r *Redis) RPush(key string, values ...interface{}) error

func (*Redis) SAdd

func (r *Redis) SAdd(key string, member interface{}) error

region set

func (*Redis) SCard

func (r *Redis) SCard(key string) (int64, error)

func (*Redis) SIsMember

func (r *Redis) SIsMember(key string, member interface{}) (bool, error)

func (*Redis) SMembers

func (r *Redis) SMembers(key string) ([]string, error)

func (*Redis) SPop

func (r *Redis) SPop(key string) (string, error)

func (*Redis) SRem

func (r *Redis) SRem(key string, members ...interface{}) error

func (*Redis) SetEX

func (r *Redis) SetEX(key string, duration int, value string) error

func (*Redis) SetKeyExpire

func (r *Redis) SetKeyExpire(key string, duration int) error

func (*Redis) SetNX

func (r *Redis) SetNX(key string, value string) error

func (*Redis) SetScript

func (r *Redis) SetScript(key string, script string, keyCount int)

func (*Redis) SetString

func (r *Redis) SetString(key string, value string) error

region string

func (*Redis) StrLen

func (r *Redis) StrLen(key string) (int64, error)

func (*Redis) ZAdd

func (r *Redis) ZAdd(key string, scoreAndmembers ...interface{}) error

region sorted set

func (*Redis) ZCard

func (r *Redis) ZCard(key string) (int64, error)

func (*Redis) ZCount

func (r *Redis) ZCount(key string, min, max int64) (int64, error)

func (*Redis) ZRank

func (r *Redis) ZRank(key string, member interface{}) ([]string, error)

func (*Redis) ZRem

func (r *Redis) ZRem(key string, members ...interface{}) error

func (*Redis) ZRevRange

func (r *Redis) ZRevRange(key string, start, end int64, withScores bool) ([][]string, error)

func (*Redis) ZRevRank

func (r *Redis) ZRevRank(key string) (int64, error)

func (*Redis) ZScore

func (r *Redis) ZScore(key string, member interface{}) (int64, error)

Jump to

Keyboard shortcuts

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