1

should I check error each step on a redis multi transaction? if some error happen, was it mean, the release command will also return error?

eg. can I :

 conn.Do("multi")
 conn.Do("set", "mm", "xx")
 reply, err := conn.Do("exec")
 if err != nil {
      ....
  }

or, should i :

  _, err := conn.Do("multi")
 if err != nil {
     ....
     return
 }
_, err := conn.Do("set", "mm", "xx")
if err != nil {
     ....
    return
 }
 reply, err := conn.Do("exec")
if err != nil {
    ....
   return
 }
ruandao
  • 410
  • 4
  • 11
  • Depends on the implementation of the `conn`'s `Do` method. – mkopriva Jul 25 '18 at 06:45
  • It is better not to ignore errors. But if you don't want to write this code snippet every time. Create a function to check error. – Himanshu Jul 25 '18 at 06:55
  • in that case you can t create helper function to check for error, 'cause you still have to return if there is an error. –  Jul 25 '18 at 07:51

1 Answers1

3

To transact, you need to Send() each command, and only Do() the EXEC. Error checking should be done for the Do() only, like so:

conn.Send("MULTI")
conn.Send("SET", "foo", "bar")
...
reply, err := conn.Do("EXEC")
if err != nil {
    ...
}
...
Itamar Haber
  • 47,336
  • 7
  • 91
  • 117