Documentation
¶
Index ¶
- type Lease
- type LeaseAttempt
- type LeaseKey
- type LeaseOwner
- type LeaseToken
- type Option
- type Service
- func (s *Service) Acquire(ctx context.Context, key LeaseKey, ttl time.Duration, owner *LeaseOwner) (LeaseAttempt, error)
- func (s *Service) CheckOwnership(ctx context.Context, lease Lease) (bool, error)
- func (s *Service) Release(ctx context.Context, lease Lease) error
- func (s *Service) Renew(ctx context.Context, lease Lease, ttl time.Duration) (Lease, bool, error)
- type TokenSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lease ¶
type Lease struct {
Key LeaseKey
Token LeaseToken
TTL time.Duration
Owner *LeaseOwner
AcquiredAt time.Time
}
Lease 表示一个已获取的锁租约。
type LeaseAttempt ¶
LeaseAttempt 描述一次 acquire 是否成功。
type LeaseOwner ¶
LeaseOwner 是锁观测与调试使用的可选拥有者元数据。
type LeaseToken ¶
type LeaseToken string
LeaseToken 是不可变的锁 token 值对象。
func MustLeaseToken ¶
func MustLeaseToken(token string) LeaseToken
MustLeaseToken 创建租约 token,输入非法时 panic。
func NewLeaseToken ¶
func NewLeaseToken(token string) (LeaseToken, error)
NewLeaseToken 创建经过校验的租约 token。
type Option ¶
type Option func(*Service)
func WithObserver ¶
func WithObserver(observer observability.LeaseObserver) Option
WithObserver 配置租约锁观测器。
func WithTokenSource ¶
func WithTokenSource(source TokenSource) Option
WithTokenSource 配置自定义 token 生成器。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(client goredis.UniversalClient, opts ...Option) *Service
NewService 基于 Redis 客户端创建租约锁服务。
func (*Service) Acquire ¶
func (s *Service) Acquire(ctx context.Context, key LeaseKey, ttl time.Duration, owner *LeaseOwner) (LeaseAttempt, error)
Acquire 使用 SET NX 语义尝试获取租约锁。
func (*Service) CheckOwnership ¶
CheckOwnership 检查给定租约是否仍然持有该锁键。
type TokenSource ¶
type TokenSource interface {
NewToken(ctx context.Context) (LeaseToken, error)
}
Click to show internal directories.
Click to hide internal directories.