1
我想知道是否有方法在指定的失效日期後從我的c#服務中清除/刷新整個緩存。我怎樣才能在c#中實現這一點?清除可配置到期的StackExchange.Redis緩存
C#
// library
using StackExchange.Redis;
public class RedisCacheService
{
// Fields
ConnectionMultiplexer _Redis = null;
IDatabase _RedisDB = null;
// ctor
public RedisCacheService(String redisConnectionString) // , DateTime ExpiryDate ? - Extracted from config
{
try
{
if (String.IsNullOrEmpty(redisConnectionString))
{
throw new Exception("The 'redisConnectionString' parameter is unassigned");
}
this._Redis = ConnectionMultiplexer.Connect(redisConString);
if (_Redis == null)
{
throw new Exception("_Redis object not initialized");
}
this._RedisDB = _Redis.GetDatabase();
// I need to set some sort of expiry config here in the constructor.
// The redisConnectionString is passed through when an instance of this class is created in the host startup and
// the redisConnectionString is extracted from the config.
}
catch (Exception e)
{
throw new Exception(e);
}
}
}
我看到了一個類似的解決方案,我可以在到期傳遞時,我竟與物體填充緩存,但我寧願要一個全局緩存澄清溶液。
任何幫助或建議,將不勝感激。
關於「關鍵空間事件」沒有事件知道。這令人敬畏的東西感謝我的讚賞! – ThatAwesomeCoder
np;)唯一的缺點是你必須在redis服務器上顯式啓用它。可以通過配置或命令行來完成。你需要'CONFIG SET通知密鑰空間事件Exe'我想 – MichaC