本文整理汇总了C#中IDatabase.Set方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.Set方法的具体用法?C# IDatabase.Set怎么用?C# IDatabase.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabase
的用法示例。
在下文中一共展示了IDatabase.Set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PutItem
public void PutItem(string key, object value, IEnumerable<string> dependentEntitySets, TimeSpan slidingExpiration, DateTimeOffset absoluteExpiration)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
if (dependentEntitySets == null)
{
throw new ArgumentNullException("dependentEntitySets");
}
_database = _redis.GetDatabase();
key = HashKey(key);
var entitySets = dependentEntitySets.ToArray();
lock (_lock)
{
try
{
_database.Set(key, new CacheEntry(value, entitySets, slidingExpiration, absoluteExpiration));
foreach (var entitySet in entitySets) {
_database.SetAdd(GetEntitySetKey(entitySet), key);
}
}
catch (Exception e)
{
OnCachingFailed(e);
}
}
}
示例2: PutItem
public void PutItem(string key, object value, IEnumerable<string> dependentEntitySets, TimeSpan slidingExpiration, DateTimeOffset absoluteExpiration)
{
key.GuardAgainstNullOrEmpty(nameof(key));
// ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null
dependentEntitySets.GuardAgainstNull(nameof(dependentEntitySets));
_database = _redis.GetDatabase();
key = HashKey(key);
// ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null
var entitySets = dependentEntitySets.ToArray();
lock (_lock)
{
try
{
foreach (var entitySet in entitySets)
{
_database.SetAdd(AddCacheQualifier(entitySet), key, CommandFlags.FireAndForget);
}
_database.Set(key, new CacheEntry(value, entitySets, slidingExpiration, absoluteExpiration));
}
catch (Exception e)
{
OnCachingFailed(e);
}
}
}
示例3: GetItem
public bool GetItem(string key, out object value)
{
key.GuardAgainstNullOrEmpty(nameof(key));
_database = _redis.GetDatabase();//connect only if arguments are valid to optimize resources
key = HashKey(key);
var now = DateTimeOffset.Now;//local variables are thread safe should be out of sync lock
try
{
value = _database.Get<CacheEntry>(key);
}
catch (Exception e)
{
value = null;
OnCachingFailed(e);
}
if (value == null) return false;
var entry = (CacheEntry)value;
if (EntryExpired(entry, now))
{
InvalidateItem(key);
value = null;
}
else
{
entry.LastAccess = now;
value = entry.Value;
// Update the entry in Redis to save the new LastAccess value.
lock (_lock)
{
try
{
_database.Set(key, entry);
}
catch (Exception e)
{
// Eventhough an error has occured, we will return true, because the retrieval of the entity was a success
OnCachingFailed(e);
}
}
return true;
}
return false;
}
示例4: MeasureSetMemoryAndTimeByRedis
/// <summary>
/// 測量寫入的時間及記憶體
/// </summary>
/// <param name="cache"></param>
private static void MeasureSetMemoryAndTimeByRedis(string cacheName, IDatabase cache)
{
System.Diagnostics.Stopwatch sh = new System.Diagnostics.Stopwatch();
sh.Start();
MemWatch mw = new MemWatch(true);
List<UserMenuInfo> menus = GetTestData();
Console.WriteLine(string.Format("CacheName:{0},MemorySizeChangeInKB:{1}", cacheName, mw.MemorySizeChangeInKB));
mw.Start();
foreach (var menu in menus)
{
cache.Set("OP-" + menu.PRG_NO, menu, TimeSpan.FromDays(1));
}
mw.Stop();
Console.WriteLine(string.Format("CacheName:{0},MemorySizeChangeInKB:{1}", cacheName, mw.MemorySizeChangeInKB));
sh.Stop();
Console.WriteLine(string.Format("CacheName:{0},Set-Milliseconds:{1}", cacheName, sh.ElapsedMilliseconds));
}