Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="keySucceed"></param>
 /// <param name="keyError"></param>
 /// <param name="hitDuration"></param>
 private void RecordRequest(string keySucceed = null, string keyError = null, string hitDuration = "1d")
 {
     if (!string.IsNullOrEmpty(keySucceed))
     {
         if (!_redisManager.Exists(keySucceed))
         {
             _redisManager.StringIncrement(keySucceed, expiry: _ConvertToTimeSpan(hitDuration));
         }
         else
         {
             _redisManager.StringIncrement(keySucceed);
         }
     }
     else
     {
         if (!_redisManager.Exists(keyError))
         {
             _redisManager.StringIncrement(keyError, expiry: _ConvertToTimeSpan(hitDuration));
         }
         else
         {
             _redisManager.StringIncrement(keyError);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="keySucceed"></param>
        /// <param name="keyError"></param>
        /// <param name="hitDuration"></param>
        private void RecordRequest(string keySucceed = null, string keyError = null, string hitDuration = "1d")
        {
            if (!string.IsNullOrEmpty(keySucceed))
            {
                if (!_redisManager.Exists(keySucceed))
                {
                    _redisManager.StringIncrement(keySucceed, expiry: _ConvertToTimeSpan(hitDuration));
                }
                else
                {
                    _redisManager.StringIncrement(keySucceed);
                }
            }
            else
            {
                if (!_redisManager.Exists(keyError))
                {
                    _redisManager.StringIncrement(keyError, expiry: _ConvertToTimeSpan(hitDuration));
                }
                else
                {
                    _redisManager.StringIncrement(keyError);
                }
            }

            TimeSpan _ConvertToTimeSpan(string timeSpan)
            {
                var l     = timeSpan.Length - 1;
                var value = timeSpan.Substring(0, l);
                var type  = timeSpan.Substring(l, 1);

                switch (type)
                {
                case "d": return(TimeSpan.FromDays(double.Parse(value)));

                case "h": return(TimeSpan.FromHours(double.Parse(value)));

                case "m": return(TimeSpan.FromMinutes(double.Parse(value)));

                case "s": return(TimeSpan.FromSeconds(double.Parse(value)));

                case "f": return(TimeSpan.FromMilliseconds(double.Parse(value)));

                case "z": return(TimeSpan.FromTicks(long.Parse(value)));

                default: return(TimeSpan.FromDays(double.Parse(value)));
                }
            }
        }
Exemplo n.º 3
0
        public async Task Remove()
        {
            string key             = "StringIncrement";
            var    stringIncrement = _redisDatabase.StringIncrement(key);
            var    result          = await _redisDatabase.RemoveAsync(key);

            Assert.AreEqual(1, result);
        }