Example #1
0
 public static bool TrySetCache(string key, byte[] bytes, TimeSpan?expiredTime = null)
 {
     try
     {
         RedisCacheAdvHelper.GetDatabase(DefaultDatabase).StringSet(key, bytes, expiredTime);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #2
0
        public static bool TryGetCache <TValue>(string key, out TValue result)
        {
            try
            {
                var value = RedisCacheAdvHelper.GetDatabase(DefaultDatabase).StringGet(key);

                if (typeof(TValue) == typeof(string))
                {
                    result = (TValue)((object)Encoding.UTF8.GetString(value));
                }
                else
                {
                    result = (TValue)((byte[])value).ToObject();
                }

                return(true);
            }
            catch (Exception)
            {
                result = default;
                return(false);
            }
        }