BB.Caching.Redis.RateLimiter.IncrementAsync C# (CSharp) Method

IncrementAsync() public static method

Increments the rate limiter at the key specified by unless the increment goes over the , in which case it returns the amount it's gone over as a negative value.
public static IncrementAsync ( string key, System.TimeSpan spanSize, System.TimeSpan bucketSize, long throttle, int increment = 1 ) : Task
key string The key where the rate limiter exists.
spanSize System.TimeSpan The full span of time being rate limited.
bucketSize System.TimeSpan The period of time that each bucket should track.
throttle long The total throttling size.
increment int How much to increment by.
return Task
        public static async Task<RedisResult> IncrementAsync(
            string key,
            TimeSpan spanSize,
            TimeSpan bucketSize,
            long throttle,
            int increment = 1)
        {
            RedisKey[] keyArgs = { key };
            RedisValue[] valueArgs =
                {
                    DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond, (long)spanSize.TotalMilliseconds,
                    (long)bucketSize.TotalMilliseconds, increment, throttle
            };

            RedisResult result = await SharedCache.Instance.GetWriteConnection(key)
                .GetDatabase(SharedCache.Instance.Db)
                .ScriptEvaluateAsync(RateLimiter.RateLimitIncrementHash, keyArgs, valueArgs);

            return result;
        }
    }