coreDb

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectDatabase

func ConnectDatabase(cfg *DatabaseCfg) (*gorm.DB, error)

ConnectDatabase 连接数据库

func GetRedisContext

func GetRedisContext() context.Context

func IfTxIsNullGetDB

func IfTxIsNullGetDB(tx *gorm.DB, ado *gorm.DB) *gorm.DB

IfTxIsNullGetDB 创建事务

func InitRedis

func InitRedis(cfg RedisConfig) (*redis.Client, error)

InitRedis 初始化 Redis 客户端

func InitSentinelRedis added in v0.0.11

func InitSentinelRedis(cfg RedisConfigSentinel) (*redis.Client, error)

InitSentinelRedis 初始化 Redis Sentinel 哨兵客户端

func IsErrRecordNotFound

func IsErrRecordNotFound(err error) bool

IsErrRecordNotFound 未找到记录

func IsRealError

func IsRealError(err error) bool

IsRealError 真实的错误

func IsRedisRealError

func IsRedisRealError(err error) bool

IsRedisRealError 判断错误是否是 真实的错误

func WithContext

func WithContext(c context.Context) context.Context

WithContext 创建上下文

Types

type DatabaseCfg added in v0.0.6

type DatabaseCfg struct {
	Username string
	Password string
	Host     string
	Port     string
	Database string
	Charset  string
	LogLevel string
	PoolSet  PoolSet
}

type PoolSet added in v0.0.6

type PoolSet struct {
	MaxIdleConn int //设置空闲连接池中连接的最大数量
	MaxOpenConn int //设置打开数据库连接的最大数量
	MaxLifeTime int //设置连接可复用的最大时间(分钟)
	MaxIdleTime int //空闲连接存活时间(分钟)
}

type RedisConfig

type RedisConfig struct {
	Addr     string // [host:port]
	Password string
	DB       int

	PoolSize     int
	MinIdleConns int
}

type RedisConfigSentinel added in v0.0.11

type RedisConfigSentinel struct {
	Hosts         []string // Sentinel 地址列表 ["ip:26379", ...]
	DB            int
	RedisPassword string // Master/Slave 密码
	SentinelPass  string // Sentinel requirepass,如果未设置则为空
	MasterName    string // sentinel monitor 的名字

	PoolSize     int
	MinIdleConns int
}

RedisConfigSentinel 哨兵模式配置

Jump to

Keyboard shortcuts

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