diff --git a/global.go b/global.go index b9d0273..16e245b 100644 --- a/global.go +++ b/global.go @@ -12,17 +12,29 @@ var ( // NewLock 从DSN创建锁 func NewLock(ctx context.Context, lockId string) (*storage_lock.StorageLock, error) { - init, err := globalLockFactory.GetOrInit(ctx, "x", func(ctx context.Context) (*storage_lock_factory.StorageLockFactory[any], error) { + init, err := GetLockFactory(ctx) + if err != nil { + return nil, err + } + return init.CreateLock(lockId) +} + +func NewLockWithOptions(ctx context.Context, lockId string, options *storage_lock.StorageLockOptions) (*storage_lock.StorageLock, error) { + init, err := GetLockFactory(ctx) + if err != nil { + return nil, err + } + return init.CreateLockWithOptions(lockId, options) +} + +func GetLockFactory(ctx context.Context) (*storage_lock_factory.StorageLockFactory[any], error) { + return globalLockFactory.GetOrInit(ctx, "x", func(ctx context.Context) (*storage_lock_factory.StorageLockFactory[any], error) { factory, err := NewLockFactory() if err != nil { return nil, err } return factory.StorageLockFactory, nil }) - if err != nil { - return nil, err - } - return init.CreateLock(lockId) } func GetGlobalLockFactory() *storage_lock_factory.StorageLockFactoryBeanFactory[string, any] {