protected void _addTrackedKey(String key, TimeSpan?slidingExpiration = null) { if (slidingExpiration != null) { long expiresUtc = RedisDataFormatUtil.ToUnixTimestamp(DateTime.UtcNow.Add(slidingExpiration.Value)); _client.SortedSetAdd(Model.CreateKey(Constants.RootKey, RedisCache.Constants.EphemeralKeysKey), expiresUtc, key); } else { _client.SetAdd(Model.CreateKey(Constants.RootKey, RedisCache.Constants.KeysKey), key); } }
public Boolean ExpireAt(String key, DateTime time) { if (key == null) { throw new ArgumentNullException("key"); } var unixTimestamp = RedisDataFormatUtil.ToUnixTimestamp(time); _connection.Send(cmd.EXPIREAT, key, unixTimestamp); return(_connection.ReadReply().IsSuccess); }
protected void _purgeExpiredKeysAsync() { Task.Factory.StartNew(() => { try { using (var rc = new RedisClient(_client.AsRedisHostInfo())) { rc.SortedSetRemoveRangeByScore(Model.CreateKey(Constants.RootKey, Constants.EphemeralKeysKey), 0, RedisDataFormatUtil.ToUnixTimestamp(DateTime.UtcNow)); } } catch { } }); }
protected void _purgeExpiredKeys() { _client.SortedSetRemoveRangeByScore(Model.CreateKey(Constants.RootKey, Constants.EphemeralKeysKey), 0, RedisDataFormatUtil.ToUnixTimestamp(DateTime.UtcNow)); }