dlock

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Path: nexss/auth/security/dlock/memory_mutex.go

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = xerr.Conflict("resource is currently locked by another instance")

ErrLocked is returned when another instance is already processing the task.

Functions

func Exclusive

func Exclusive[Req, Res any](m Mutex, ttl time.Duration, keyFn func(Req) string) action.Middleware[Req, Res]

Exclusive wraps an action so it only executes if it acquires the lock. If the lock is held by another node, it returns ErrLocked immediately (fast fail).

Types

type MemoryMutex

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

MemoryMutex provides an in-memory implementation of Mutex for single-node / testing.

func NewMemoryMutex

func NewMemoryMutex() *MemoryMutex

func (*MemoryMutex) TryLock

func (m *MemoryMutex) TryLock(_ context.Context, key string, ttl time.Duration) (bool, error)

func (*MemoryMutex) Unlock

func (m *MemoryMutex) Unlock(_ context.Context, key string) error

type Mutex

type Mutex interface {
	TryLock(ctx context.Context, key string, ttl time.Duration) (bool, error)
	Unlock(ctx context.Context, key string) error
}

Mutex defines a distributed lock interface (e.g., Redis, NATS, Postgres).

type RedisMutex

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

RedisMutex implements action.Mutex using Redis SET with NX option.

func NewRedisMutex

func NewRedisMutex(client *redis.Client) *RedisMutex

func (*RedisMutex) TryLock

func (m *RedisMutex) TryLock(ctx context.Context, key string, ttl time.Duration) (bool, error)

func (*RedisMutex) Unlock

func (m *RedisMutex) Unlock(ctx context.Context, key string) error

Jump to

Keyboard shortcuts

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