dbcache

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(debug ...bool)

func NewLocalCache

func NewLocalCache() *localCache

func NewRedisCache

func NewRedisCache() *redisCache

func RedisBiz

func RedisBiz() *jredis.Jredis

func RedisBizInit

func RedisBizInit(host, port, auth string, module ...string)

func RedisCacheInit

func RedisCacheInit(host, port, auth string, module ...string)

func RegisterCache

func RegisterCache(c Cache)

RegisterCache 缓存注册

func RegisterDb

func RegisterDb(dsn string, dbname string, isDefault ...bool)

func SETExpire

func SETExpire(e int)

func SetDebug

func SetDebug(debug ...bool)

Types

type Cache

type Cache interface {
	Set(key, value string, expire ...int) bool
	Get(key string) string
	Expire(key string, expire int) int
	Del(key string) int
}

type Dao

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

func NewDb

func NewDb(dbname ...string) *Dao

func (*Dao) Begin added in v0.0.3

func (d *Dao) Begin() Daoer

func (*Dao) ClearCache

func (d *Dao) ClearCache()

func (*Dao) Commit added in v0.0.3

func (d *Dao) Commit() Daoer

func (*Dao) Create

func (d *Dao) Create(data interface{}) (int64, error)

func (*Dao) DB

func (d *Dao) DB() *gorm.DB

func (*Dao) DryRun

func (d *Dao) DryRun() *gorm.DB

func (*Dao) EXEC

func (d *Dao) EXEC() (int64, error)

func (*Dao) Fetch

func (d *Dao) Fetch(result interface{}) error
Example
db := NewDb()
var user1 User
db.DB().AutoMigrate(&User{})
stmt := db.DryRun().Find(&user1, 1).Statement
tag := "users000"
err := db.SetTag(tag).PrepareSql(stmt.SQL.String(), stmt.Vars...).Fetch(&user1)
fmt.Println(user1.Id, err)

var users []User
// 会话模式
stmt = db.DryRun().Find(&users).Statement
db.SetTag(tag).PrepareSql(stmt.SQL.String(), stmt.Vars...).Fetch(&users)
fmt.Println("result", len(users) > 0)
Output:

	1 <nil>
result true

func (*Dao) PrepareSql

func (d *Dao) PrepareSql(sql string, params ...interface{}) Daoer

func (*Dao) Rollback added in v0.0.3

func (d *Dao) Rollback() Daoer

func (*Dao) SetKey

func (d *Dao) SetKey(key string) Daoer

单独的key管理,相当于直接操作redis的key

func (*Dao) SetTag

func (d *Dao) SetTag(tag string) Daoer

二级缓存 tag随机获取一个值val,使用val和sql组合生成key存缓存

type Daoer

type Daoer interface {
	DB() *gorm.DB
	DryRun() *gorm.DB
	SetTag(tag string) Daoer
	SetKey(key string) Daoer
	PrepareSql(sql string, params ...interface{}) Daoer
	Fetch(result interface{}) error
	EXEC() (int64, error)
	Create(data interface{}) (int64, error)
	ClearCache()
	Begin() Daoer
	Rollback() Daoer
	Commit() Daoer
}

Jump to

Keyboard shortcuts

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