diff --git a/commands_test.go b/commands_test.go index 327cc26..9796a37 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1298,12 +1298,15 @@ var _ = Describe("Commands", func() { }) It("should BRPopLPush", func() { - rPush := client.RPush("list1", "a", "b", "c") - Expect(rPush.Err()).NotTo(HaveOccurred()) + _, err := client.BRPopLPush("list1", "list2", time.Second).Result() + Expect(err).To(Equal(redis.Nil)) - bRPopLPush := client.BRPopLPush("list1", "list2", 0) - Expect(bRPopLPush.Err()).NotTo(HaveOccurred()) - Expect(bRPopLPush.Val()).To(Equal("c")) + err = client.RPush("list1", "a", "b", "c").Err() + Expect(err).NotTo(HaveOccurred()) + + v, err := client.BRPopLPush("list1", "list2", 0).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(v).To(Equal("c")) }) It("should LIndex", func() { diff --git a/multi.go b/multi.go index 9b9df75..320e78e 100644 --- a/multi.go +++ b/multi.go @@ -174,6 +174,9 @@ func (c *Multi) execCmds(cn *conn, cmds []Cmder) error { // Parse number of replies. line, err := readLine(cn) if err != nil { + if err == Nil { + err = TxFailedErr + } setCmdsErr(cmds[1:len(cmds)-1], err) return err } @@ -182,10 +185,6 @@ func (c *Multi) execCmds(cn *conn, cmds []Cmder) error { setCmdsErr(cmds[1:len(cmds)-1], err) return err } - if len(line) == 3 && line[1] == '-' && line[2] == '1' { - setCmdsErr(cmds[1:len(cmds)-1], TxFailedErr) - return TxFailedErr - } var firstCmdErr error diff --git a/parser.go b/parser.go index 43274fc..94fa597 100644 --- a/parser.go +++ b/parser.go @@ -231,9 +231,16 @@ func readLine(cn *conn) ([]byte, error) { if isPrefix { return line, errReaderTooSmall } + if isNilReply(line) { + return nil, Nil + } return line, nil } +func isNilReply(b []byte) bool { + return len(b) == 3 && (b[0] == '$' || b[0] == '*') && b[1] == '-' && b[2] == '1' +} + func readN(cn *conn, n int) ([]byte, error) { var b []byte if cap(cn.buf) < n { @@ -251,17 +258,6 @@ func parseErrorReply(cn *conn, line []byte) error { return errorf(string(line[1:])) } -func isNilReply(b []byte) bool { - return len(b) == 3 && b[1] == '-' && b[2] == '1' -} - -func parseNilReply(cn *conn, line []byte) error { - if isNilReply(line) { - return Nil - } - return fmt.Errorf("redis: can't parse nil reply: %.100", line) -} - func parseStatusReply(cn *conn, line []byte) ([]byte, error) { return line[1:], nil } @@ -282,8 +278,6 @@ func readIntReply(cn *conn) (int64, error) { switch line[0] { case errorReply: return 0, parseErrorReply(cn, line) - case stringReply: - return 0, parseNilReply(cn, line) case intReply: return parseIntReply(cn, line) default: