Documentation
¶
Index ¶
Constants ¶
View Source
const (
MSG_UNLOCK string = "RELEASE"
)
View Source
const (
READ_TAG string = "GLOCK_GRWMUTEX_READ_TAG"
)
Variables ¶
View Source
var ( ErrNotObtain = errors.New("not obtain the lock") ErrNotObtainedLock = errors.New("had not obtain the lock") ErrWrongTag = errors.New("the lock does not belong to you") ErrNotExists = errors.New("the lock does not exists") )
View Source
var (
ErrSubTimeout = errors.New("subscribe timeout")
)
Functions ¶
This section is empty.
Types ¶
type GMutex ¶
type GMutex struct {
// contains filtered or unexported fields
}
type GRWMutex ¶
type GRWMutex struct {
// contains filtered or unexported fields
}
func (*GRWMutex) RUnLock ¶
RUnLock 解锁,解除RLock一次
如果该实例获取RLock不成功则不应该调用该方法,否则会有解锁其他相同key的RLock的风险 ,因为RLock的tag都是一样的
func (*GRWMutex) TryLock ¶
TryLock 写加锁,尝试WLock加锁
@maxWaiTime 最长等待时间,如果为0则只会获取一次,小于0会返回ErrNotObtain @holdingTime 持锁时间,获取到锁后生效,为本次获取锁的持有时间,如果没选,则是无限时长,开启看门狗策略
type GReLock ¶
type GReLock struct {
// contains filtered or unexported fields
}
type Glock ¶
type Glock struct {
// contains filtered or unexported fields
}
func (*Glock) GetRWMutex ¶
GetRWMutex GRWMutex, 获取key的读写锁GRWMutex
func (*Glock) GetReLock ¶
GetReLock GReLock, 获取key tag的可重入锁GReLock
@tag 相同的key tag的锁互为可重入,如tag为空,则使用glock的tag(默认为 LocalIP() + ":" + PId())
如果要基于goroutine使用的可重入锁,那么可以使用 GetReLock(key,LocalIP() + ":" + PId() + ":" + GoId())
func (*Glock) GetReLockWithGoroutine ¶
GetReLockWithGoroutine, 获取key groutineid为tag的可重入锁GReLock
同一个groutine可重入,等价于GetReLock(key,LocalIP() + ":" + PId() + ":" + GoId())
type GlockOptions ¶
type GlockOptions struct {
// contains filtered or unexported fields
}
type Option ¶
type Option func(opts *GlockOptions)
func WithLogger ¶
func WithLogger(logger log.FieldsLogger) Option
func WithPrefix ¶
func WithUnPrefix ¶
func WithUnPrefix() Option
func WithWatchDogTimeout ¶
type RedisGlockOperate ¶
type RedisGlockOperate interface {
/*可重入方式获取锁,获取成功返回0,获取失败返回锁对应pttl
获取锁应该设置对应的key val 并加上过期时间ttl,如果锁已存在则应该计数+1*/
ObtainLock(key, val string, ttl time.Duration) (int64, error)
/*释放锁,释放成功返回1,锁不存在返回0,val不对返回-1
释放锁应该计数-1,如果计数归零应删除对应key,并向publishKey推送publishMsg消息*/
ReleaseLock(key, val, publishKey, publishMsg string) (int, error)
/*刷新锁,刷新成功返回1,锁不存在返回0,val不对返回-1
刷新锁应该刷新key val 对应过期时间为 ttl*/
RenewLock(key, val string, ttl time.Duration) (int, error)
/*订阅channel渠道并接受相应订阅消息
返回ErrSubTimeout错误为订阅超时*/
SubscribeAndReceiveMessage(publishKey string, timeout time.Duration) (msg string, err error)
}
type WatchDog ¶
type WatchDog struct {
// contains filtered or unexported fields
}
func NewWatchDog ¶
func NewWatchDog(watchDogTimeout time.Duration, watchFor WatchForFunc, logger log.FieldsLogger) *WatchDog
type WatchForFunc ¶
Click to show internal directories.
Click to hide internal directories.