public async Task ReleaseAsync(int permits) { var preparedScript = LuaScriptLoader.GetScript(LockScript.SEMAPHORE_RELEASE); var result = await _redisDb.ScriptEvaluateAsync(preparedScript, new { lock_key = GetLockKey(), channel = GetChannelName(), permits = permits, }); }
public async Task <bool> TryAcquireAsync(int quantity, int millisecondsTimeout) { var preparedScript = LuaScriptLoader.GetScript(LockScript.SEMAPHORE_ACQUIRE); var result = await _redisDb.ScriptEvaluateAsync(preparedScript, new { lock_key = GetLockKey(), quantity = quantity, }); return(string.Equals("1", result.ToString())); }
protected virtual async Task <bool> RenewExpirationAsync() { var preparedScript = LuaScriptLoader.GetScript(LockScript.MUTEX_LOCK_RENEW); var result = await RedisDb.ScriptEvaluateAsync(preparedScript, new { key = LockKey, field = LockId, expire = InternalLockLeaseTime, }); return(string.Equals("1", result.ToString())); }
protected virtual async Task InvokUnlockScriptAsync(int leaseTime) { var preparedScript = LuaScriptLoader.GetScript(LockScript.MUTEX_LOCK_RELEASE); var result = await RedisDb.ScriptEvaluateAsync(preparedScript, new { lock_key = LockKey, lock_id = LockId, expire = leaseTime, channel = ChannelName, msg = LockPubSub.UNLOCK_MESSAGE, }); }
protected override async Task InvokUnlockScriptAsync(int leaseTime) { var preparedScript = LuaScriptLoader.GetScript(LockScript.WRITE_LOCK_RELEASE); var result = await RedisDb.ScriptEvaluateAsync(preparedScript, new { lock_key = LockKey, channel = ChannelName, read_unlock_msg = LockPubSub.READ_UNLOCK_MESSAGE, expire = leaseTime, lock_id = LockId }); }
protected override async Task <bool> RenewExpirationAsync() { var preparedScript = LuaScriptLoader.GetScript(LockScript.READ_LOCK_RENEW); var result = await RedisDb.ScriptEvaluateAsync(preparedScript, new { lock_key = LockKey, timeout_prefix = LockKey, expire = InternalLockLeaseTime, lock_id = LockId }); return(string.Equals("1", result.ToString())); }
protected override async Task InvokUnlockScriptAsync(int leaseTime) { var preparedScript = LuaScriptLoader.GetScript(LockScript.READ_LOCK_RELEASE); var result = await RedisDb.ScriptEvaluateAsync(preparedScript, new { lock_key = LockKey, channel = ChannelName, timeout_key = GetReadWriteTimeoutNamePrefix(), timeout_prefix = LockKey, unlock_msg = LockPubSub.UNLOCK_MESSAGE, lock_id = LockId }); }
protected virtual async Task <int?> InvokLockScriptAsync(int leaseTime) { var preparedScript = LuaScriptLoader.GetScript(LockScript.MUTEX_LOCK_ACQUIRE); var result = await RedisDb.ScriptEvaluateAsync(preparedScript, new { lock_key = LockKey, lock_id = LockId, expire = leaseTime, }); if (result.IsNull) { return(null); } return(int.Parse(result.ToString())); }
protected override async Task <int?> InvokLockScriptAsync(int leaseTime) { var preparedScript = LuaScriptLoader.GetScript(LockScript.READ_LOCK_ACQUIRE); var result = await RedisDb.ScriptEvaluateAsync(preparedScript, new { lock_key = LockKey, timeout_key = GetReadWriteTimeoutNamePrefix(), expire = leaseTime, lock_id = LockId, write_lock = GetWriteLockName() }); if (result.IsNull) { return(null); } return(int.Parse(result.ToString())); }