godis
godis copied to clipboard
MULTI..EXEC transactions and asynchronous Call commands
Hi,
This pull request addresses three issues:
-
When a MULTI..EXEC transaction fails because of a WATCH condition, an error is returned by ReadAll. It is difficult to test this error to see if it was due to an aborted transaction or something else. I have named the error as ErrMultiAborted, so now you can just do a check like so:
if err == redis.ErrMultiAborted { // transaction aborted, try again
-
The Call method of an AsyncClient cannot return any errors, so I removed the err return value. It calls Write in bytes.Buffer, but the docs for that method explicitly say it will never return an err (it just has the return type to match the io.Writer interface). Removing this lets careful people know it is okay to assume the call will succeed.
-
When using WATCH with MULTI..EXEC transactions, the normal pattern is:
WATCH foo GET foo MULTI do stuff using the value of foo that is now guaranteed to not change EXEC
AsyncClient handles the MULTI..EXEC part great, but it is a bit verbose to run the commands that happen before the MULTI is issued. This adds a SyncCall to AsyncClient that works more like Call from Client. It fails if there are already commands in the queue.
Thanks,
Russ