I'm trying use Redis INCR and the incremented value to be used as a field in a Hash from C# using StackExchange.Redis. This question points similar to what I need, but in Node.
The below is something like I need.
ITransaction transation = m_connection.GetDatabase()
.CreateTransaction();
Task<long> incrementTask = transation.StringIncrementAsync(sequenceNumberRedisKey);
if (await transation.ExecuteAsync())
{
long sequenceNumber = await incrementTask;
await transation.HashSetAsync(responseRedisKey, sequenceNumber, response);
}
Note that sequenceNumber is the result of the first operation I intend to do in the transaction.
The code seems like the transaction executes and commits before I even do any of my operations.
- Is this the way to do multiple operations in one transaction?
- Is this the way I could use the result of operation 1 (StringIncrementAsync) in operation 2 (HashSetAsync) ?
- How do I rollback the sequence number increment if HashSetAsync returns false?
- Why is there no explicit commit?