You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are considering adding distributed lock interface design to the framework's main library, while implementing specific implementations in community components. The community components can provide distributed lock implementations based on Redis and MySQL.
Describe alternatives you've considered
For the distributed lock interface definition, here's an initial proposal:
// Package gdlock provides distributed locking functionality.package gdlock
import (
"context""time"
)
// DistributedLock defines the interface for distributed lock operations.// It provides methods for acquiring and managing distributed locks across multiple processes/servers.typeDistributedLockinterface {
// Lock acquires a lock with the given key and TTL.// It blocks until the lock is acquired or the context is canceled.Lock(ctx context.Context, keystring, ttl time.Duration, optsLockOptions) (LockInstance, error)
// LockFunc acquires a lock and executes the provided function within the lock's scope.// The lock is automatically released after the function execution.LockFunc(ctx context.Context, keystring, ttl time.Duration, optsLockOptions, ffunc(ctx context.Context) error) (LockInstance, error)
// TryLock attempts to acquire a lock without blocking.// It returns immediately if the lock is already held by another process.TryLock(ctx context.Context, keystring, ttl time.Duration, optsLockOptions) (LockInstance, error)
// TryLockFunc attempts to acquire a lock and execute the provided function if successful.// It returns immediately without executing the function if the lock is already held.TryLockFunc(ctx context.Context, keystring, ttl time.Duration, optsLockOptions, ffunc(ctx context.Context) error) (LockInstance, error)
}
// LockInstance represents an acquired lock instance.// It provides methods for managing the lifecycle of an acquired lock.typeLockInstanceinterface {
// Unlock releases the acquired lock.Unlock(ctx context.Context) error// Refresh extends the TTL of the lock.Refresh(ctx context.Context, newTTL time.Duration) error// GetTTL retrieves the remaining time-to-live for the lock.GetTTL(ctx context.Context) (time.Duration, error)
}
// LockOptions defines the configuration options for lock acquisition.typeLockOptionsstruct {
// Reason provides a descriptive reason for acquiring the lock.// This is useful for debugging and monitoring purposes.Reasonstring
}
Additional
No response
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem?
Option Yes
Describe the solution you'd like
We are considering adding distributed lock interface design to the framework's main library, while implementing specific implementations in community components. The community components can provide distributed lock implementations based on Redis and MySQL.
Describe alternatives you've considered
For the distributed lock interface definition, here's an initial proposal:
Additional
No response
The text was updated successfully, but these errors were encountered: