locklease

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package locklease 定义分布式租约锁的通用领域端口。

本包不依赖 Redis 或其他存储实现,只提供锁规格、锁身份、租约值对象和 Manager 接口。业务系统可以在自己的包内定义具体锁规格,再由 infra adapter 实现该端口。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Identity

type Identity struct {
	Name string
	Key  string
}

Identity 描述一个具体锁实例。

type Lease

type Lease struct {
	Key   string
	Token string
}

Lease 表示一个已成功获取的锁租约。

type Manager

type Manager interface {
	AcquireSpec(ctx context.Context, spec Spec, key string, ttlOverride ...time.Duration) (*Lease, bool, error)
	ReleaseSpec(ctx context.Context, spec Spec, key string, lease *Lease) error
}

Manager 是应用代码依赖的、与 Redis 无关的租约锁端口。

type Spec

type Spec struct {
	Name        string
	Description string
	DefaultTTL  time.Duration
}

Spec 描述一个具有语义的租约锁工作负载。

func (Spec) Identity

func (s Spec) Identity(key string) Identity

Identity 根据业务 key 构造一个具体锁身份。

Directories

Path Synopsis
Package redisadapter 提供基于 Redis 的 locklease.Manager 实现。
Package redisadapter 提供基于 Redis 的 locklease.Manager 实现。

Jump to

Keyboard shortcuts

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