コード例 #1
0
        public static async Task <bool> TryHashSetAsync <T>(this IDatabase cache,
                                                            string key,
                                                            string field,
                                                            T record,
                                                            TimeSpan?cacheExpiration = null,
                                                            ILog log = null)
        {
            try
            {
                await cache.HashSetAsync(key, field, CacheSerializer.Serialize(record));

                if (cacheExpiration.HasValue)
                {
                    await cache.KeyExpireAsync(key, cacheExpiration);
                }

                return(true);
            }
            catch (RedisConnectionException ex)
            {
                log?.Warning("Redis cache is not available", ex);
                // ignoring the errors
                return(false);
            }
        }
コード例 #2
0
        public static async Task <T> TryHashGetAsync <T>(this IDatabase cache,
                                                         string key,
                                                         string field,
                                                         ILog log = null)
        {
            try
            {
                var record = await cache.HashGetAsync(key, field);

                if (record.HasValue)
                {
                    return(CacheSerializer.Deserialize <T>(record));
                }
            }
            catch (RedisConnectionException ex)
            {
                log?.Warning("Redis cache is not available", ex);
            }

            return(default(T));
        }