@@ -263,6 +263,10 @@ var _ = Describe("JSON Commands", Label("json"), func() {
263
263
Expect (err ).NotTo (HaveOccurred ())
264
264
Expect (res ).To (Equal ("OK" ))
265
265
266
+ resArr , err := client .JSONArrIndex (ctx , "doc1" , "$.store.book[?(@.price<10)].size" , 20 ).Result ()
267
+ Expect (err ).NotTo (HaveOccurred ())
268
+ Expect (resArr ).To (Equal ([]int64 {1 , 2 }))
269
+
266
270
res , err = client .JSONGetWithArgs (ctx , "get3" , & redis.JSONGetArgs {Indent : "-" }).Result ()
267
271
Expect (err ).NotTo (HaveOccurred ())
268
272
Expect (res ).To (Equal (`{-"a":1,-"b":2}` ))
@@ -673,6 +677,54 @@ var _ = Describe("JSON Commands", Label("json"), func() {
673
677
Expect (cmd2 .Val ()[0 ]).To (Or (Equal ([]interface {}{"boolean" }), Equal ("boolean" )))
674
678
})
675
679
})
680
+
681
+ Describe ("JSON Nil Handling" , func () {
682
+ It ("should return redis.Nil for non-existent key" , func () {
683
+ _ , err := client .JSONGet (ctx , "non-existent-key" , "$" ).Result ()
684
+ Expect (err ).To (Equal (redis .Nil ))
685
+ })
686
+
687
+ It ("should return redis.Nil for non-existent path in existing key" , func () {
688
+ err := client .JSONSet (ctx , "test-key" , "$" , `{"a": 1, "b": "hello"}` ).Err ()
689
+ Expect (err ).NotTo (HaveOccurred ())
690
+
691
+ _ , err = client .JSONGet (ctx , "test-key" , "$.nonexistent" ).Result ()
692
+ Expect (err ).To (Equal (redis .Nil ))
693
+ })
694
+
695
+ It ("should distinguish empty array from nil" , func () {
696
+ err := client .JSONSet (ctx , "test-key" , "$" , `{"arr": [], "obj": {}}` ).Err ()
697
+ Expect (err ).NotTo (HaveOccurred ())
698
+
699
+ // Empty array should return the array, not nil
700
+ val , err := client .JSONGet (ctx , "test-key" , "$.arr" ).Result ()
701
+ Expect (err ).NotTo (HaveOccurred ())
702
+ Expect (val ).To (Equal ("[[]]" ))
703
+
704
+ // Non-existent field should return nil
705
+ _ , err = client .JSONGet (ctx , "test-key" , "$.missing" ).Result ()
706
+ Expect (err ).To (Equal (redis .Nil ))
707
+ })
708
+
709
+ It ("should handle multiple paths with mixed results" , func () {
710
+ err := client .JSONSet (ctx , "test-key" , "$" , `{"a": 1, "b": 2}` ).Err ()
711
+ Expect (err ).NotTo (HaveOccurred ())
712
+
713
+ // Path that exists
714
+ val , err := client .JSONGet (ctx , "test-key" , "$.a" ).Result ()
715
+ Expect (err ).NotTo (HaveOccurred ())
716
+ Expect (val ).To (Equal ("[1]" ))
717
+
718
+ // Path that doesn't exist
719
+ _ , err = client .JSONGet (ctx , "test-key" , "$.c" ).Result ()
720
+ Expect (err ).To (Equal (redis .Nil ))
721
+ })
722
+
723
+ AfterEach (func () {
724
+ // Clean up test keys
725
+ client .Del (ctx , "test-key" , "non-existent-key" )
726
+ })
727
+ })
676
728
}
677
729
})
678
730
0 commit comments