Skip to content

Commit

Permalink
refactor(JSONCmd): tweak wrongly handled reply
Browse files Browse the repository at this point in the history
  • Loading branch information
unknowntpo committed Jan 28, 2024
1 parent 7faf9f7 commit 92c36fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 13 additions & 1 deletion rueidiscompat/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10812,7 +10812,10 @@ func testAdapterCache(resp3 bool) {
Expect(cmd2.Val()).To(Equal(int64(1)))

cmd3 := adapter.JSONGet(ctx, "del1", "$")
Expect(cmd3.Err()).NotTo(HaveOccurred())
// go-redis's test assertion is wrong.
// based on the result from redis/redis-stack:7.2.0-v3,
// cmd3.Err() should be rueidis.Nil, not nil
Expect(cmd3.Err()).To(Equal(rueidis.Nil))
Expect(cmd3.Val()).To(HaveLen(0))
})

Expand Down Expand Up @@ -10941,6 +10944,15 @@ func testAdapterCache(resp3 bool) {
cmd2 := adapter.JSONNumIncrBy(ctx, "incr3", "$..a[1]", float64(1))
Expect(cmd2.Err()).NotTo(HaveOccurred())
Expect(cmd2.Val()).To(Equal(`[3,0]`))

cmd3 := adapter.JSONSet(ctx, "incr4", "$", `{"a": [1, 2], "b": {"a": [0, -1], "c": "z"}, "c": 2}`)
Expect(cmd3.Err()).NotTo(HaveOccurred())
Expect(cmd3.Val()).To(Equal("OK"))

cmd4 := adapter.JSONNumIncrBy(ctx, "incr4", "$..c", float64(1))
Expect(cmd4.Err()).NotTo(HaveOccurred())
// for NaN field, it should be null
Expect(cmd4.Val()).To(Equal(`[3,null]`))
})

It("should JSONNumIncrBy with $", Label("json.numincrby", "json"), func() {
Expand Down
7 changes: 3 additions & 4 deletions rueidiscompat/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3515,10 +3515,6 @@ func newJSONCmd(res rueidis.RedisResult) *JSONCmd {
cmd := &JSONCmd{}
msg, err := res.ToMessage()
if err != nil {
if err == rueidis.Nil {
cmd.SetVal("")
return cmd
}
cmd.SetErr(err)
return cmd
}
Expand Down Expand Up @@ -3548,6 +3544,9 @@ func newJSONCmd(res rueidis.RedisResult) *JSONCmd {
for i, e := range arr {
anyE, err := e.ToAny()
if err != nil {
if err == rueidis.Nil {
continue
}
cmd.SetErr(err)
return cmd
}
Expand Down

0 comments on commit 92c36fa

Please sign in to comment.