ActionSuccess callback with IncrementKey does not work in transaction:
public class Article
{
public long Id { get; set; }
public string Name { get; set; }
}
[Test]
public void Can_create_article_with_autoincremental-id()
{
Article a = new Article() { Name = "I Love Writing Test" };
using (var trans = Redis.CreateTransaction())
{
trans.QueueCommand(r => r.IncrementValue("id:article"), id => a.Id = id);
trans.QueueCommand(r => r.Store<Article>(a));
trans.Commit();
}
Assert.That(Redis.Get<Article>("1").Id,Is.Equal("1"));
}
Redis transactions are all executed at the same time where callbacks only fire after the entire transaction has been completed. So you cannot use the return values in the callbacks within the same transaction in another part of that transaction.
If you just wanted to store an Article with an autoincrementing Id counter, you can simply do:
There’s no need for the transaction for this. To use values from Redis inside a transaction which will only execute if none of the values have changed use the WATCH command. See my earlier answer for an example.