lock

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

type Lock interface {
	// Lock try  get a lock for given key
	Lock(ctx context.Context, key string) (observer LockResult, acquired bool)
	// Release remove lock for given key
	Release(ctx context.Context, key string)
	// NotifyAndRelease remove lock for given key and notify all clients waiting for result
	// SharedResponse allows sharing the same buffer across all waiting requests without copying
	NotifyAndRelease(ctx context.Context, key string, res *response.SharedResponse)
}

Lock is responding for collapsing request for same object

func Create added in v0.18.0

func Create(lockCfg *config.LockCfg, lockTimeout int) Lock

type LockResult

type LockResult struct {
	ResponseChan chan *response.Response // channel on which you get response
	Cancel       chan bool               // channel for notify about cancel of waiting
	Error        error                   // error when creating error
}

LockResult contain struct

type MemoryLock

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

MemoryLock is in memory lock for single mort instance

func NewMemoryLock

func NewMemoryLock() *MemoryLock

NewMemoryLock create a new empty instance of MemoryLock

func (*MemoryLock) Lock

func (m *MemoryLock) Lock(ctx context.Context, key string) (LockResult, bool)

Lock create unique entry in memory map

func (*MemoryLock) NotifyAndRelease

func (m *MemoryLock) NotifyAndRelease(_ context.Context, key string, sharedResponse *response.SharedResponse)

NotifyAndRelease tries notify all waiting goroutines about response. Uses SharedResponse to allow all waiting requests to share the same buffer without creating full copies, significantly reducing memory usage for duplicate requests (e.g., 10 waiters × 5MB = 50MB → 5MB).

func (*MemoryLock) Release

func (m *MemoryLock) Release(_ context.Context, key string)

Release remove entry from memory map

type NopLock

type NopLock struct {
}

NopLock will never collapse any request

func NewNopLock

func NewNopLock() *NopLock

NewNopLock create lock that do nothing

func (*NopLock) Lock

func (l *NopLock) Lock(_ context.Context, _ string) (LockResult, bool)

Lock always return that lock was acquired

func (*NopLock) NotifyAndRelease

func (l *NopLock) NotifyAndRelease(_ context.Context, _ string, _ *response.SharedResponse)

NotifyAndRelease do nothing

func (*NopLock) Release

func (l *NopLock) Release(_ context.Context, _ string)

Release do nothing

type RedisLock added in v0.18.0

type RedisLock struct {
	LockTimeout int
	// contains filtered or unexported fields
}

RedisLock is in Redis lock for single mort instance

func NewRedisCluster added in v0.18.0

func NewRedisCluster(redisAddress []string, clientConfig map[string]string) *RedisLock

func NewRedisLock added in v0.18.0

func NewRedisLock(redisAddress []string, clientConfig map[string]string) *RedisLock

NewRedis create connection to redis and update it config from clientConfig map

func (*RedisLock) Close added in v0.34.0

func (m *RedisLock) Close() error

Close closes the Redis client and cleans up all resources. This should be called when the RedisLock is no longer needed to prevent goroutine leaks.

func (*RedisLock) Lock added in v0.18.0

func (m *RedisLock) Lock(ctx context.Context, key string) (LockResult, bool)

Lock create unique entry in Redis map

func (*RedisLock) NotifyAndRelease added in v0.18.0

func (m *RedisLock) NotifyAndRelease(ctx context.Context, key string, sharedResponse *response.SharedResponse)

NotifyAndRelease tries notify all waiting goroutines about response Delegates to MemoryLock which uses SharedResponse for zero-copy buffer sharing

func (*RedisLock) Release added in v0.18.0

func (m *RedisLock) Release(ctx context.Context, key string)

Release remove entry from Redis map

Jump to

Keyboard shortcuts

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