StackExchange / StackExchange.Redis

General purpose redis client
https://stackexchange.github.io/StackExchange.Redis/
Other
5.88k stars 1.51k forks source link

Update Transactions.md #2575

Closed DavidKlempfner closed 11 months ago

DavidKlempfner commented 11 months ago

Using await for an async method.

mgravell commented 11 months ago

No. That's not correct here, and will effectively jam your execution (I would say block your thread, but the async, threadless version of blocking a thread)

If you want to await it to get a result, you must do that after the execute, by storing the pending result in a local:

bar pending = tran.HashSetAsync(custKey, "UniqueID", newId);
bool committed = tran.Execute();
bar result = await pending;
DavidKlempfner commented 11 months ago

No. That's not correct here, and will effectively jam your execution (I would say block your thread, but the async, threadless version of blocking a thread)

If you want to await it to get a result, you must do that after the execute, by storing the pending result in a local:

bar pending = tran.HashSetAsync(custKey, "UniqueID", newId);
bool committed = tran.Execute();
bar result = await pending;

I understand now, thanks!