redisadapter

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: 7 Imported by: 0

Documentation

Overview

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

该 adapter 复用 component-base 的 redis/lease 基础能力,负责把通用 locklease.Spec 和 locklease.Identity 映射为 Redis SET NX 租约锁。 调用方可以通过 KeyFunc 注入自己的 keyspace 规则,从而避免把项目级 Redis key 设计泄漏到基础库。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyFunc

type KeyFunc func(string) string

KeyFunc 将逻辑锁身份 key 映射为具体 Redis key。

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 将通用 locklease.Manager 端口适配到 Redis 租约锁基础能力。

func NewManager

func NewManager(client redis.UniversalClient, keyFunc KeyFunc, opts ...Option) *Manager

NewManager 创建一个基于 Redis 的 locklease.Manager。

func (*Manager) Acquire

func (m *Manager) Acquire(ctx context.Context, identity locklease.Identity, ttl time.Duration) (*locklease.Lease, bool, error)

Acquire 尝试获取一个具体锁身份。

func (*Manager) AcquireSpec

func (m *Manager) AcquireSpec(ctx context.Context, spec locklease.Spec, key string, ttlOverride ...time.Duration) (*locklease.Lease, bool, error)

AcquireSpec 根据语义锁规格获取租约。

func (*Manager) Release

func (m *Manager) Release(ctx context.Context, identity locklease.Identity, lease *locklease.Lease) error

Release 释放一个已获取的具体锁租约。

func (*Manager) ReleaseSpec

func (m *Manager) ReleaseSpec(ctx context.Context, spec locklease.Spec, key string, lease *locklease.Lease) error

ReleaseSpec 根据语义锁规格释放租约。

type Option

type Option func(*managerOptions)

Option 配置 Redis 租约锁管理器。

func WithObserver

func WithObserver(observer observability.LeaseObserver) Option

WithObserver 配置底层 Redis lease 观测器。

func WithTokenSource

func WithTokenSource(source redislease.TokenSource) Option

WithTokenSource 配置自定义 token 来源,主要用于确定性测试。

Jump to

Keyboard shortcuts

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