Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FactoryOptions ¶
type FactoryOptions struct { // IDGenerator a function generate unique id for each lock, if not IDGenerator func() string // DefaultTimeout default lock release time, if not passed `DefaultTimeout` will be 5 minutes. DefaultTimeout time.Duration }
FactoryOptions custom params to replace default value
type ILock ¶
type ILock interface { // Lock lock a resource, if failed will wait until success or reach the max times. Lock(ctx context.Context) // Realease release lock if lock id is matched. Release(ctx context.Context) // TryLock try to lock resource once. TryLock(ctx context.Context) (err error, success bool) // Extend extend lock time. Extend(ctx context.Context) (err error, success bool) // Get lock left seconds. TTL(ctx context.Context) }
ILock Lock client interface.
type ILockFactory ¶
ILockFactory A lock factory interface.
func NewLockFactory ¶
func NewLockFactory(ctx context.Context, redisClient IRedisClient, options *FactoryOptions) (ILockFactory, error)
NewLockFactory generate a lock factory.
type IRedisClient ¶
type IRedisClient interface { RunExtendCmd(script, key, lockID string, expiration time.Duration) (err error, success bool) RunUnlockCmd(script, key, lockID string) (err error, success bool) SetNX(key, lockID string, expiration time.Duration) (err error, success bool) }
IRedisClient Redis client interface.
Click to show internal directories.
Click to hide internal directories.