dlock

package
v0.0.0-...-a36dcc1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: MIT Imports: 8 Imported by: 0

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 RandomVal

type RandomVal struct{}

func (*RandomVal) GetValue

func (v *RandomVal) GetValue() interface{}

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()

func (*RedisLocker) UnLock

func (m *RedisLocker) UnLock(ctx context.Context) (isDel bool)

UnLock unlock ok return true or false by lua script for atomic cmd(get->del)

type UUIDVal

type UUIDVal struct{}

func (*UUIDVal) GetValue

func (v *UUIDVal) GetValue() interface{}

Jump to

Keyboard shortcuts

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