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
-
RedisLockProvider
- Implements
- Inherited Members
- Extension Methods
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
getDatabaseFunc<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
keystringThe identifier of the resource to lock.
timeoutTimeSpanThe maximum duration to keep retrying before giving up.
Returns
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
keystringThe identifier of the token to release.