db

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConflict = errors.New("LockConflict")
)

Functions

This section is empty.

Types

type DBLock

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

func NewDBLock

func NewDBLock(db *gorm.DB, ttl time.Duration) *DBLock

func (*DBLock) Lock

func (r *DBLock) Lock(ctx context.Context, key string) (keyLock interface{}, err error)

func (*DBLock) UnLock

func (r *DBLock) UnLock(ctx context.Context, keyLock interface{}) error

type ResourceLock

type ResourceLock struct {
	ID       uint   `gorm:"primarykey;AUTO_INCREMENT"`
	Resource string `gorm:"type:varchar(255);unique"`
	// 假设一种情况,A请求拿到了锁,但是本身任务太长,超过了锁时间,B请求拿到了锁,并且开始执行任务,A任务完成了会去解锁,这个时候就意外地把B刚拿到的锁解了
	// Lock成功应该生成一个所有者ID,保存到表里面并且返回,unlock的时候需要指定这个所有者ID匹配了去解锁,这样可以防止解锁了其他人的锁
	LockerID  string `gorm:"type:varchar(255);index:idx_locker_id"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

ResourceLock is the model of ResourceLock.

func (ResourceLock) TableName

func (ResourceLock) TableName() string

TableName returns the table name of the Partition.

Jump to

Keyboard shortcuts

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