I've got several question about using transactions from StackExchange.Redis:
{1}
hashtag and second command's key has {2}
hashtag.Execute()
/ExecuteAsync()
returns false
? Only when set conditions were not met? Could it return false
if there were no conditions set?Execute()
/ExecuteAsync()
throw or just return false
? Should I also check commands' tasks (assuming that commands are fully correct and normally are not expected to throw) or they will just be cancelled?Unfortunately the doc doesn't explain #2 and #3 in details.
Using a single AWS EC2 instance, Redis was able to achieve 1,200,000 transactions per second at <1 msec (sub millisecond) latency.
Redis Transactions allow the execution of a group of commands in a single step, they are centered around the commands MULTI , EXEC , DISCARD and WATCH . Redis Transactions make two important guarantees: All the commands in a transaction are serialized and executed sequentially.
Redis transaction is also atomic. Atomic means either all of the commands or none are processed.
Unlike pipelines, pipelines use special commands to mark the beginning and the end of the transaction, and the server also can queue the commands from a transaction (so the client can send one at a time). So transactions are stateful on the server, it actually keeps track of an ongoing transaction.
I've digged a bit into StackExchange.Redis source code and played with the driver, here are my observations:
ITransaction
instanceExecute()
/ExecuteAsync()
The answers seem to be the following:
Execute()
/ExecuteAsync()
returns false
in two cases: when transaction was discarded because conditions were not met, and when driver failed to queue the command (for example because of server OOM). All command tasks will be marked as canceled. Also Execute()
/ExecuteAsync()
does not return false
if one of the commands failed during execution (for example, because of wrong type operation).Execute()
/ExecuteAsync()
will throw an exception and all commands tasks will remain in "waiting for activation" state.To sum it up, command tasks should only be checked if Execute()
/ExecuteAsync()
returned true
: every task will either contain a result or an error (see Exception
property).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With