private async Task <byte[]> GetAndRefreshAsync(string key, bool getData, CancellationToken token = default(CancellationToken)) { if (key == null) { throw new ArgumentNullException(nameof(key)); } token.ThrowIfCancellationRequested(); // This also resets the LRU status as desired. // TODO: Can this be done in one operation on the server side? Probably, the trick would just be the DateTimeOffset math. object[] results; byte[] value = null; if (getData) { var ret = await _redisClient.HMGetAsync <byte[]>(key, AbsoluteExpirationKey, SlidingExpirationKey, DataKey); results = new object[] { ret[0] == null ? null : Encoding.UTF8.GetString(ret[0]), ret[1] == null ? null : Encoding.UTF8.GetString(ret[1]), value = ret[2] }; } else { results = await _redisClient.HMGetAsync(key, AbsoluteExpirationKey, SlidingExpirationKey); } // TODO: Error handling if (results.Length >= 2) { MapMetadata(results, out DateTimeOffset? absExpr, out TimeSpan? sldExpr); await RefreshAsync(key, absExpr, sldExpr, token); } if (results.Length >= 3) { return(value); } return(null); }