Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ILockerVal ¶
type ILockerVal interface {
GetValue() interface{} // get rand value for del lock
}
type RedisLocker ¶
type RedisLocker struct {
// contains filtered or unexported fields
}
func New ¶
func New(rdb *redis.Client, key, tag string, val ILockerVal, retryTimes int, retryInterval, expiration time.Duration, isWatch bool) *RedisLocker
New get a RedisLocker instance
func (*RedisLocker) Lock ¶
func (m *RedisLocker) Lock(ctx context.Context) (err error, isGainLock bool)
Lock block Lock util retryTimes per retryInterval
Example ¶
wg := &sync.WaitGroup{}
tags := []string{"A", "B", "C", "D", "E"}
wg.Add(len(tags))
for _, tag := range tags {
go func(tag string) {
MockTestLock(tag)
wg.Done()
}(tag)
}
wg.Wait()
func (*RedisLocker) TryLock ¶
func (m *RedisLocker) TryLock(ctx context.Context) (err error, isGainLock bool)
TryLock unblock try lock
Example ¶
wg := &sync.WaitGroup{}
tags := []string{"A", "B", "C", "D", "E"}
wg.Add(len(tags))
for _, tag := range tags {
go func(tag string) {
MockTestTryLock(tag)
wg.Done()
}(tag)
}
wg.Wait()
Click to show internal directories.
Click to hide internal directories.