在StackExchange.Redis(source)上进行交易的示例为:
var newId = CreateNewId();
var tran = db.CreateTransaction();
tran.AddCondition(Condition.HashNotExists(custKey, "UniqueID"));
tran.HashSetAsync(custKey, "UniqueID", newId);
bool committed = tran.Execute();
// ^^^ if true: it was applied; if false: it was rolled back
是否需要等待HashSetAsync
调用返回的任务?该文档指出:“直到Execute
(或ExecuteAsync
)完成之后,才能知道每个操作的结果”。如果该操作没有返回任何数据,是否可以保证Execute
返回后总是一个已完成的任务,因此不需要等待,或者是否有可能也需要等待该操作?也就是说,下面是否多余?
var hashSetTask = tran.HashSetAsync(custKey, "UniqueID", newId);
bool committed = tran.Execute();
if (committed)
await hashSetTask;