I'm using Stackexchange.Redis on a cluster ASP.Net Core servers, and having some trouble with transactions.
The following code is supposed to delete a field with the key "hashItemID" from two hashes, "HashA" and "HashB", but only if it exists in both:
var hashAKey = "HashA";
var hashBKey = "HashB";
var id = "hashItemID";
var tran = redis.Database.CreateTransaction();
// Only delete the item if it exists in both hashes
var hashBCondition = tran.AddCondition(Condition.HashExists(hashBKey, id));
var hashACondition = tran.AddCondition(Condition.HashExists(hashAKey, id));
tran.HashDeleteAsync(hashBKey, id);
tran.HashDeleteAsync(hashAKey, id);
var deleted = await tran.ExecuteAsync();
if (!deleted)
{
logger.LogWarning("Failed to delete '{ID}'. HashAResult: {A}, HashBResult: {B}", id, hashACondition.WasSatisfied, hashBCondition.WasSatisfied);
}
Occasionally this code will fail with the log:
Failed to delete 'hashItemID'. HashAResult: True, HashBResult: True
I was under the impression that transactions only fail if their conditions aren't met, is that true?
Looking at network and performance metrics, there's no timeouts or high memory usage that could be contributing to this.