本文整理汇总了C#中IDatabase.SetAdd方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.SetAdd方法的具体用法?C# IDatabase.SetAdd怎么用?C# IDatabase.SetAdd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabase
的用法示例。
在下文中一共展示了IDatabase.SetAdd方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompleteTask
public static void CompleteTask(IDatabase db, string task)
{
db.SetRemove("running", task);
db.HashSet("task-" + task, new[] { new HashEntry("complete", DateTime.Now.ToString("dd/MM/yy HH:mm:ss.fff")) });
db.SetAdd("complete", task);
var workflow = db.HashGet("task-" + task, "workflow");
var remaining = db.HashDecrement("workflow-" + workflow, "tasksRemaining");
if (remaining.Equals(0))
{
db.Publish("workflowComplete", workflow);
return;
}
var children = db.SetMembers("children-" + task);
foreach (var child in children)
{
db.SetRemove("parents-" + child, task);
if (db.SetLength("parents-" + child).Equals(0))
{
Direct.PushTask(db, child);
}
}
Console.WriteLine("completed: " + task);
}
示例2: GetWorkflowId
public static long GetWorkflowId(IDatabase db)
{
if (db.SetLength("workflowIds").Equals(0))
{
var tempId = db.HashIncrement("ids", "currentWorkflowId");
db.SetAdd("workflowIds", tempId);
}
var workflowId = (long)db.SetPop("workflowIds");
return workflowId;
}
示例3: PopTask
public static string PopTask(IDatabase db)
{
var task = db.ListRightPop("submitted");
if (task.Equals(RedisValue.Null)) return null;
db.SetAdd("running", task);
db.HashSet("task-" + task, new[] { new HashEntry("running", DateTime.Now.ToString("dd/MM/yy HH:mm:ss.fff")) });
Console.WriteLine("popped: " + task);
return task;
}
示例4: CheckSetContent
private static void CheckSetContent(IDatabase db, List<string> expected, string state, bool condition = true)
{
var toRequeue = new List<string>();
while (db.SetLength(state) != 0)
{
toRequeue.Add(db.SetPop(state));
}
foreach (var item in expected)
{
if(condition)
Assert.IsTrue(toRequeue.Contains(item));
else
Assert.IsFalse(toRequeue.Contains(item));
}
foreach (var temp in toRequeue)
{
db.SetAdd(state, temp);
}
}
示例5: 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);
}
}
}
示例6: 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);
}
}
}