示例#1
0
        private async Task SetKeyExpirationAsync(CSRedisClient client, string cacheKey, Func <ICacheItemExpiration> expiration)
        {
            var expiry = GetExpirationTime(expiration);

            if (expiry != null)
            {
                await client.ExpireAsync(cacheKey, (int)expiry.Value.TotalSeconds);
            }
            else
            {
                await client.ExpireAsync(cacheKey, TimeSpan.MaxValue);
            }
        }
示例#2
0
        private async Task RefreshAsync(string key, DateTimeOffset?absExpr, TimeSpan?sldExpr, CancellationToken token = default(CancellationToken))
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            token.ThrowIfCancellationRequested();

            // Note Refresh has no effect if there is just an absolute expiration (or neither).
            TimeSpan?expr = null;

            if (sldExpr.HasValue)
            {
                if (absExpr.HasValue)
                {
                    var relExpr = absExpr.Value - DateTimeOffset.Now;
                    expr = relExpr <= sldExpr.Value ? relExpr : sldExpr;
                }
                else
                {
                    expr = sldExpr;
                }
                await _redisClient.ExpireAsync(key, expr ?? TimeSpan.Zero);

                // TODO: Error handling
            }
        }
 public bool TryGetValue(string key, out byte[] value)
 {
     if (redisDB.HExists(this.Id, key))
     {
         value = redisDB.HGet <byte[]>(this.Id, key);
         redisDB.ExpireAsync(this.Id, config.ExpireSeconds);
         return(true);
     }
     else
     {
         value = null;
         return(false);
     }
 }