Esempio n. 1
0
        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,
            });
        }
Esempio n. 2
0
        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()));
        }
Esempio n. 3
0
        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()));
        }
Esempio n. 4
0
        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,
            });
        }
Esempio n. 5
0
        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
            });
        }
Esempio n. 6
0
        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()));
        }
Esempio n. 7
0
        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
            });
        }
Esempio n. 8
0
        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()));
        }
Esempio n. 9
0
        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()));
        }