# Class RedisLockProvider

Namespace
  adas_core.Application.Services.Caching

Assembly
  adas-core.Application.dll

Lock distribuido en Redis. Usa token por adquisición (owner) y liberación segura con script Lua: borra la key solo si el valor coincide.

    public class RedisLockProvider : ILockProvider

Inheritance
  object
  RedisLockProvider

Implements
  ILockProvider

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Constructors

### RedisLockProvider(Func<IDatabase?>)

Lock distribuido en Redis. Usa token por adquisición (owner) y liberación segura con script Lua: borra la key solo si el valor coincide.

    public RedisLockProvider(Func<IDatabase?> getDatabase)

#### Parameters

`getDatabase` Func<IDatabase>

## Methods

### AcquireAsync(string, TimeSpan)

Attempts to acquire a distributed lock for the specified key using Redis, retrying until the timeout expires. Returns `false` if the Redis database is unavailable or if the lock cannot be acquired within the given timeout.

    public Task<bool> AcquireAsync(string key, TimeSpan timeout)

#### Parameters

`key` string

  The identifier of the resource to lock.

`timeout` TimeSpan

  The maximum duration to keep retrying before giving up.

#### Returns

Task<bool>

  `true` if the lock was successfully acquired; otherwise, `false`.

### ReleaseAsync(string)

Asynchronously releases the token associated with the specified key by removing it from the in-memory token store and executing a Lua release script against Redis. If the key is not found in the local store, or the Redis database is unavailable, the method returns without performing any further action.

    public Task ReleaseAsync(string key)

#### Parameters

`key` string

  The identifier of the token to release.

#### Returns

Task