Documentation
¶
Index ¶
- func Get(c runtimecontract.Container) (datacontract.DistributedLock, error)
- func GetOrPanic(c runtimecontract.Container) datacontract.DistributedLock
- func Lock(ctx context.Context, c runtimecontract.Container, key string, ...) error
- func TryLock(ctx context.Context, c runtimecontract.Container, key string, ...) (bool, error)
- func Unlock(ctx context.Context, c runtimecontract.Container, key string) error
- func WithLock(ctx context.Context, c runtimecontract.Container, key string, ...) error
- type DistributedLock
- type DistributedLockConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
func Get(c runtimecontract.Container) (datacontract.DistributedLock, error)
Get returns the distributed lock service from the container. Get 从容器获取分布式锁服务。
func GetOrPanic ¶
func GetOrPanic(c runtimecontract.Container) datacontract.DistributedLock
GetOrPanic returns the distributed lock service from the container and panics on failure. GetOrPanic 从容器获取分布式锁服务,失败 panic。
func Lock ¶
Lock acquires a lock using the distributed lock service from the container. Lock 使用容器中的分布式锁获取锁。
func TryLock ¶
func TryLock(ctx context.Context, c runtimecontract.Container, key string, ttl time.Duration) (bool, error)
TryLock tries to acquire a lock using the distributed lock service from the container. TryLock 使用容器中的分布式锁尝试获取锁。
func Unlock ¶
Unlock releases a lock using the distributed lock service from the container. Unlock 使用容器中的分布式锁释放锁。
func WithLock ¶
func WithLock(ctx context.Context, c runtimecontract.Container, key string, ttl time.Duration, fn func() error) error
WithLock executes a function while holding a distributed lock. WithLock 使用容器中的分布式锁包裹执行函数。
Example:
err := dlock.WithLock(ctx, c, "order:42", 5*time.Second, func() error {
return processOrder(ctx, 42)
})
Types ¶
type DistributedLock ¶
type DistributedLock = datacontract.DistributedLock
DistributedLock is the top-level alias of the distributed lock contract. DistributedLock 是分布式锁契约的顶层别名。
type DistributedLockConfig ¶
type DistributedLockConfig = datacontract.DistributedLockConfig
DistributedLockConfig is the top-level alias of the distributed lock config contract. DistributedLockConfig 是分布式锁配置契约的顶层别名。