示例#1
0
        /// <summary>
        /// Acquire the specified key, total, rate and requstCount.
        /// </summary>
        /// <returns>The acquire.</returns>
        /// <param name="key">Key.</param>
        /// <param name="total">Total.</param>
        /// <param name="rate">Rate.</param>
        /// <param name="requstCount">Requst count.</param>
        public bool Acquire(string key, long total, double rate, int requstCount = 1)
        {
            var res = _redisManager.ExecLuaScript(lua_script, new RedisKey[] { key }, new RedisValue[]
            {
                total, rate, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), requstCount
            });

            return((bool)res);
        }
        /// <summary>
        /// Acquire the specified key, total, perSecond and requstCount.
        /// </summary>
        /// <returns>The acquire.</returns>
        /// <param name="key">Key.</param>
        /// <param name="total">Total.</param>
        /// <param name="perSecond">Per second.</param>
        /// <param name="requstCount">Requst count.</param>
        public bool Acquire(string key, long total, int perSecond, int requstCount = 1)
        {
            var res = _redisManager.ExecLuaScript(script, new RedisKey[] { key }, new RedisValue[]
            {
                total, perSecond, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), requstCount
            });

            var intRes = (int)res;

            return(intRes >= 0);
        }